Failure-Driven Cancellation
A child scope failure cancels the remaining work before the caller receives ScopeError.
function* launchCampaign() {
yield* branch(function* sendCampaign() {
yield* spawn(function* sendEmailBatch() {
yield* sleep(1000);
throw new Error("email provider failed");
});
yield* spawn(function* refreshAudience() {
yield* sleep(6000);
});
yield* sleep(6000);
});
}launchCampaign calls branch(...), opening the sendCampaign child scope.
The sendCampaign scope contains sendCampaign, sendEmailBatch, and refreshAudience.
When sendEmailBatch throws, the sendCampaign scope cancels the sleeping work.
After the scope closes, launchCampaign receives ScopeError at the branch(...) call.