fun-task
fun-task copied to clipboard
Task.sequentially()
trafficstars
Same signature as in Task.parallel() but runs tasks in sequence.
https://github.com/russiann/promise-sequential seems like I'm not the only one who thought about this idea :)
I needed this them I build one function:
function sequenceTasks(tasks) {
return Task.chainRec((next, done, pair) => {
const [result, rest] = pair;
if (rest.length === 0)
return Task.of(done(result));
return rest[0].map(x => next([
result.concat(x),
rest.slice(1)
]));
}, [[], tasks]);
}