Failure-Driven Cancellation
failure-triggered structured cancellation
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 enters branch to run sendCampaign.
sendEmailBatch and refreshAudience both belong to the sendCampaign scope.
After sendEmailBatch throws, branch cancels the still-sleeping refreshAudience and sendCampaign processes.
The branch call then throws the scope failure, interrupting launchCampaign.