(items, consumer)
| 3 | * and it will call them sequentially, one after another |
| 4 | */ |
| 5 | export function sequence(items, consumer) { |
| 6 | const results = []; |
| 7 | const runner = () => { |
| 8 | const item = items.shift(); |
| 9 | if (item) { |
| 10 | return consumer(item) |
| 11 | .then((result) => { |
| 12 | results.push(result); |
| 13 | }) |
| 14 | .then(runner); |
| 15 | } |
| 16 | |
| 17 | return Promise.resolve(results); |
| 18 | }; |
| 19 | |
| 20 | return runner(); |
| 21 | } |
no test coverage detected