-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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 preMainLoop/postMainLoop functions #22621
Conversation
5b8d810
to
c73154e
Compare
@@ -149,12 +149,21 @@ LibraryJSEventLoop = { | |||
clearInterval(id); | |||
}, | |||
|
|||
$registerPostMainLoop: (f) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment that as an optimization, this does not include MainLoop but instead checks for it at runtime and does nothing?
Separately, I wonder if we can do better than this. We could in theory add a "weak linking" mechanism, that would add some code only if MainLoop was actually included. Though if it's complicated it might not be worth it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly I don't think we have such a weak linking mechanism today. The way I did it here I think is the closest thing we have to weak linking in JS code.
c73154e
to
43ca757
Compare
Rather than having code from e.g SDL, etc, in event loop code use a callback registration system.
43ca757
to
f094bf2
Compare
@@ -149,12 +149,23 @@ LibraryJSEventLoop = { | |||
clearInterval(id); | |||
}, | |||
|
|||
$registerPostMainLoop: (f) => { | |||
// Does nothing unless $MainLoop is included/used. | |||
typeof MainLoop != 'undefined' && MainLoop.postMainLoop.push(f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typeof MainLoop != 'undefined' && MainLoop.postMainLoop.push(f); | |
MainLoop?.postMainLoop.push(f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly I don't think the ? operator works like that (i.e. it doesn't work on top level things):
$ node
Welcome to Node.js v18.20.3.
Type ".help" for more information.
> a?.foo
Uncaught ReferenceError: a is not defined
>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining:
Optional chaining cannot be used on a non-declared root object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh sorry. That is unfortunate, I wonder why it has that restriction.
Rather than having code from e.g SDL, etc, in event loop code use a callback registration system.