26 lines
430 B
Markdown
26 lines
430 B
Markdown
### chainAsync
|
|
|
|
Chains 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();
|
|
};
|
|
```
|
|
|
|
```js
|
|
chainAsync([
|
|
next => {
|
|
console.log('0 seconds');
|
|
setTimeout(next, 1000);
|
|
},
|
|
next => {
|
|
console.log('1 second');
|
|
}
|
|
]);
|
|
```
|