shajaraFlow ExplorerScope-Owned Work
English

Scope-Owned Work

Work owned by a child scope must finish before the caller continues.

branch(commitArticle)spawn(updateSearchIndex)owned processbranch waits for child scopepublishArticlependingupdateSearchIndexpendingcommitArticlepending
function* publishArticle() {
  const result = yield* branch(function* commitArticle() {
    yield* spawn(function* updateSearchIndex() {
      yield* sleep(1000);
    });

    return "published";
  });

  return result;
}
publishArticle calls branch(...), opening the commitArticle child scope.
updateSearchIndex is spawned inside the commitArticle scope.
commitArticle returns published before updateSearchIndex finishes.
publishArticle continues from branch(...) only after updateSearchIndex finishes.