redux-saga/effects#spawn JavaScript Examples
The following examples show how to use
redux-saga/effects#spawn.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: index.js From jc-calendar with MIT License | 6 votes |
/**
* Spawns given sagas, restarting them if they throw any uncaught error.
* @param {...GeneratorFunction} sagas The sagas to spawn and keep alive
*/
function* keepAlive(...sagas) {
yield all(
sagas.map((saga) =>
spawn(function* () {
while (true) {
try {
// Start the worker saga
yield call(saga);
// If it finishes, exit
break;
} catch (e) {
// If an error happens it will be logged
// and the loop will restart the saga
console.groupCollapsed(
`%cSaga ${saga.name} crashed and will be restarted...`,
`
font-size: 600;
color: #DC2626;
background-color: #FECACA;
padding: 0.125rem 0.25rem;
border-radius: 0.125rem;
`
);
console.error(e);
console.groupEnd();
}
}
})
)
);
}