Files: ca90b5ca0579ebdcc0635288bce4978e3fb200f5 / test / test-79-npm / batch / batch.js
435 bytesRaw
1 | ; |
2 | |
3 | var Batch = require('batch'); |
4 | var batch = new Batch(); |
5 | |
6 | batch.concurrency(4); |
7 | |
8 | var ids = [ 4, 7, 12, 25 ]; |
9 | |
10 | ids.forEach(function () { |
11 | batch.push(function (done) { |
12 | setTimeout(function () { |
13 | done(); |
14 | }, 100); |
15 | }); |
16 | }); |
17 | |
18 | var passed = 0; |
19 | |
20 | batch.on('progress', function () { |
21 | passed += 1; |
22 | }); |
23 | |
24 | batch.end(function (error) { |
25 | if (error) { |
26 | throw error; |
27 | } |
28 | if (passed > 3) { |
29 | console.log('ok'); |
30 | } |
31 | }); |
32 |
Built with git-ssb-web