Scope-Managed Objects
scope-managed future and channel life cycles
function* resumeCheckout() {
const [ticket, updates] = yield* branch(function* openSession() {
const [ticket] = yield* future<string>();
const [updates] = yield* channel<string, never>(0);
yield* sleep(1000);
return [ticket, updates];
});
yield* sleep(1000);
try { yield* wait(ticket); }
catch (error) { observeCanceled(error); }
yield* sleep(1000);
try { yield* tryReceive(updates); }
catch (error) { observeRevoked(error); }
return "owned objects closed";
} openSession creates ticket and updates inside its child scope.
resumeCheckout can still use ticket and updates, but the runtime objects stay owned by the scope that created them.
When the openSession child scope converges, it cancels the unfinished future and revokes the open channel.
Later wait and tryReceive only observe those terminal states.