Merge pull request #37 from RobertAKARobin/robertakarobin-dev

Added async function chain
This commit is contained in:
Angelos Chalaris
2017-12-13 12:12:42 +02:00
committed by GitHub

View File

@ -0,0 +1,14 @@
### Chain asynchronous functions
Loop through an array of functions containing asynchronous events, calling `next` when each asynchronous event has completed.
```js
const chainAsync = fns => { let curr = 0; const next = () => fns[curr++](next); next(); }
/*
chainAsync([
next => { console.log('0 seconds'); setTimeout(next, 1000); },
next => { console.log('1 second'); setTimeout(next, 1000); },
next => { console.log('2 seconds');}
])
*/
```