wait until cancelled
yehonadav-feel opened this issue · comments
yonadav commented
i have a side effects saga that executes effects by takeEvery(setStateChange, genEffectHandler)
and when the parent of that saga is done i'd like to cancel all of these effects.
export default function* sagaRoot() {
const tasks = [];
...
tasks.push(yield fork(sagaSideEffects));
try {
...
} finally {
// root ended - cancelling forked children!
yield all(tasks.map((task) => cancel(task)));
...
}
}
export function* sagaSideEffects() {
...
const tasks = [];
try {
tasks.push(
yield takeEvery(setState.type, setStateEffectHandler),
...
);
// so now i need to wait until the root is cancelling me.
// is there a less stupid way to wait ?
// like yield take(cancelled) ?
while (yield delay(999999999));
} catch (e) {
errorHandlerService.send({
error: e,
section: 'watchMeetingSideEffects'
});
} finally {
if (yield cancelled()) {
yield all(tasks.map((task) => cancel(task)));
}
...
}
}
is there a good way to 'wait until cancelled' ?
Mateusz Burzyński commented
You'd have to introduce smth like block
:
function block() {
return call(() => new Promise(() => {}))
}
// ...
yield block()