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 ability to evaluate append an operation to the current frame #878

Open
cowboyd opened this issue Jan 5, 2024 · 0 comments
Open

Add ability to evaluate append an operation to the current frame #878

cowboyd opened this issue Jan 5, 2024 · 0 comments
Assignees

Comments

@cowboyd
Copy link
Member

cowboyd commented Jan 5, 2024

There are certain cases when you want to add operations to the front of a frame to execute teardown.

each()

for (let x of yield* each(items)) {
  break;
  yield* each.next();
}

yield* thing(x); 

The yield* each(items) will create a subscription that needs to be disposed of when the loop exits.

When leaving the loop, JavaScript will invoke the return() method of the iterator returned by yield* each(), so there is an opportunity to insert the teardown of the subscription there. It is not enough to use ensure() because that will execute at the very end of the frame, but we don't know how long that could take. Instead, we need the teardown of the subscription to be the next thing that happens in the frame, including before it returns. In this case, it would start evaluating thing(x), but before it did, it would run the subscription teardown.

@cowboyd cowboyd self-assigned this Jan 5, 2024
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

No branches or pull requests

1 participant