scope 管理的对象
future 和 channel 会留在创建它们的 scope 归属下。
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) { observeUnfulfilled(error); }
yield* sleep(1000);
try { yield* tryReceive(updates); }
catch (error) { observeRevoked(error); }
return "owned objects closed";
}openSession 在 openSession scope 内创建 ticket 和 updates。
branch(...) 返回时,openSession scope 已关闭,resumeCheckout 收到这些句柄。
openSession scope 关闭时,ticket 会变成 unfulfilled,updates 会被撤销。
后续 wait(...) 会观察到 ticket 的 unfulfilled 结果,tryReceive(...) 会观察到 updates 已被撤销。