Add ability to evaluate append an operation to the current frame
cowboyd opened this issue · 0 comments
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.