function retry(fx, cb) {
const left = createStore(10)
const noLeft = left.map(s => !s)
left.on(fx.finally, x => x - 1)
guard({
source: sample(left, fx.doneData, (count, task) => ({count, task})),
filter: ({count, taskState}) =>
taskState === 'OK' || taskState === 'ERROR' || count === 0,
target: fx,
})
guard({
source: fx,
filter: noLeft,
target: cb,
})
}
const fetchUserReposFx = createEffect()
fetchUserReposFx.use(async _ => {
const req = await fetch('https://jsonplaceholder.typicode.com/todos/1')
return req.json()
})
retry(fetchUserReposFx, console.log)