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

(breaking) Sync lifecycle #2

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

(breaking) Sync lifecycle #2

wants to merge 6 commits into from

Conversation

HDegroote
Copy link
Collaborator

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 where watch 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 that open will be called at some point, which is what we want anyway.

Note: the change is backwards compatible (verified with blind-peer)

@HDegroote
Copy link
Collaborator Author

HDegroote commented Jan 24, 2025

Updated to use the more common sync initialisation pattern, where it is initialised in the constructor, and torn down in a sync destroy method
(it is now a breaking change)

@HDegroote HDegroote changed the title Sync lifecycle (simplify) (breaking) Sync lifecycle Jan 24, 2025
index.js Outdated
[...this.store.cores.map.values()].map(this._oncoreopenBound)
)
// Give time to add event handlers
setImmediate(() => {
Copy link
Contributor

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?

Copy link
Collaborator Author

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

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.

2 participants