Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for different codal message bus listener flags #10054

Merged
merged 2 commits into from
Jul 26, 2024

Conversation

riknoll
Copy link
Member

@riknoll riknoll commented Jul 26, 2024

This adds simulator support for the various CODAL message bus listener modes. These modes are:

  • MESSAGE_BUS_LISTENER_QUEUE_IF_BUSY - the default mode that queues events if an event handler is busy. this has been the only supported mode in our simulator until now
  • MESSAGE_BUS_LISTENER_DROP_IF_BUSY - events are dropped if fired while the event handler is already executing
  • MESSAGE_BUS_LISTENER_REENTRANT - events are always fired immediately, even if the event handler is already executing
  • MESSAGE_BUS_LISTENER_IMMEDIATE - this is used by the scheduler and throws an error if used elsewhere

this is part of the fix for microsoft/pxt-microbit#5709, i'll have two more prs (one in pxt-common-packages and one in pxt-microbit)

@@ -563,13 +571,43 @@ namespace pxsim {

export type EventIDType = number | string;

class EventHandler {
private busy = 0;
constructor(public handler: RefAction, public flags: number) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit pedantic, but wondering if the flags parameter will be able to pass on multiple flags or just one at a time since it has type number?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm matching the codal naming here, but actually numbers can hold up to 32 flags (one for each bit)

@@ -3,6 +3,14 @@
namespace pxsim {
const MIN_MESSAGE_WAIT_MS = 200;
let tracePauseMs = 0;

enum MessageListenerFlags {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wanted to put this here for reference: https://github.com/lancaster-university/codal-core/blob/509086cc8590465041b15493ab52b56e7071c110/inc/core/CodalListener.h#L33-L41

Also, just wanted to know why we're not including all of the defined flags here?

Copy link
Member Author

@riknoll riknoll Jul 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

those other ones are internal only AFAIK

pxtsim/runtime.ts Outdated Show resolved Hide resolved
Co-authored-by: Sarah Rietkerk <49178322+srietkerk@users.noreply.github.com>
@riknoll riknoll merged commit ee5e19f into master Jul 26, 2024
6 checks passed
@riknoll riknoll deleted the dev/riknoll/message-bus-listeners branch July 26, 2024 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants