shajaraFlow ExplorerRecovery Boundary
English

Recovery Boundary

guard(...) routes a resumable(...) failure to a recovery handler.

guard(reviewListing)resumable(scanPhotos)recovery valueresumable valuepublishListingpendingscanPhotospendingreviewListingpendingapproveManuallypending
function* publishListing() {
  yield* guard(
    function* reviewListing() {
      const approval = yield* resumable(
        function* scanPhotos() {
          yield* sleep(1000);
          throw new Error("scanner offline");
        },
      );

      yield* recordApproval(approval);
    },

    function* approveManually(error) {
      yield* sleep(1000);
      return [true, `manual approval: ${error.kind}`];
    },
  );
}
publishListing enters guard(...), and reviewListing waits at resumable(...).
scanPhotos throws while reviewListing is waiting.
approveManually handles the failure at the guard boundary.
The recovery value returns to reviewListing as approval.