This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let allConcurrent = function(limit, generators){ | |
| return new Promise(function(resolveAll){ | |
| let plan = generators.map((generator)=>({ value: undefined, executed: false, settled: false, generator: generator })); | |
| let executeBatch = () => { | |
| plan | |
| .filter(({ settled, executed })=> !executed || (executed && !settled)) | |
| .slice(0, limit) | |
| .filter(({ executed }) => !executed) | |
| .map(planItem => { | |
| planItem.executed = true; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const combine = (...arrays) | |
| => [].concat(...arrays); | |
| const compact = arr | |
| => arr.filter(el => el); | |
| const contains = (() => Array.prototype.includes | |
| ? (arr, value) => arr.includes(value) | |
| : (arr, value) => arr.some(el => el === value) | |
| )(); |