Last active
June 14, 2018 10:29
-
-
Save kvasdopil/468251c3aa9e0653e4292a0b55a610c8 to your computer and use it in GitHub Desktop.
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
| function concat(args, func, cb) { | |
| const results = []; | |
| const errors = []; | |
| args.forEach(arg => func(arg, (err, files) => { | |
| if (err) { | |
| errors.push(err); | |
| } else { | |
| results.push(files); | |
| } | |
| if (results.length + errors.length === args.length) { | |
| cb(errors.length ? errors : null, results.reduce((a, i) => a.concat(i), [])); | |
| } | |
| })); | |
| } | |
| function expect(a, b) { | |
| console.log(a, b); | |
| } | |
| const callOrder = []; | |
| const iteratee = (x, cb) => { | |
| setTimeout(() => { | |
| callOrder.push(x); | |
| let y = x; | |
| const r = []; | |
| while (y > 0) { | |
| r.push(y); | |
| y -= 1; | |
| } | |
| cb(null, r); | |
| }, x * 25); | |
| }; | |
| concat([1, 3, 2], iteratee, (err, results) => { | |
| expect(results, [1, 2, 1, 3, 2, 1]); | |
| expect(callOrder, [1, 2, 3]); | |
| expect(err, null); | |
| }); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment