-
Notifications
You must be signed in to change notification settings - Fork 0
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
(breaking) Sync lifecycle #2
base: main
Are you sure you want to change the base?
Conversation
Updated to use the more common sync initialisation pattern, where it is initialised in the constructor, and torn down in a sync destroy method |
index.js
Outdated
[...this.store.cores.map.values()].map(this._oncoreopenBound) | ||
) | ||
// Give time to add event handlers | ||
setImmediate(() => { |
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.
why is the immediate needed?
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.
Should have been queueMicroTask + needed a check on whether it was already destroyed. Pushed a fix.
The reason is to give time to add event-handlers before the background processing starts
The initial approach was extracted from blind-peer, where ready/close lifecycle was async. But I've realised that the lifecycle is actually sync: the invariant of passive-core-watcher is that it calls the
open
function for all cores that are open (for those wherewatch
returns true)The async lifecycle added the unneeded invariant that
open
is called for all already-opened cores BEFORE ready resolves. Now it just guarantees thatopen
will be called at some point, which is what we want anyway.Note: the change is backwards compatible (verified with blind-peer)