shajaraFlow ExplorerScope-Managed Objects
English

Scope-Managed Objects

Futures and channels stay owned by the scope that creates them.

branch(openSession)branch waits for openSessionticket, updateswait(ticket)tryReceive(updates)resumeCheckoutpendingupdatesopenticketopenSessionpending
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 creates ticket and updates inside the openSession scope.
When branch(...) returns, the openSession scope has closed and resumeCheckout receives the handles.
When the openSession scope closes, ticket settles as unfulfilled and the updates channel is revoked.
Later wait(...) observes ticket as unfulfilled, and tryReceive(...) observes updates as revoked.