1 | var f = function (i, next) {
|
2 | setTimeout(function () {
|
3 | if (i === 20) {
|
4 | next(new Error('my exception'));
|
5 | } else {
|
6 | next(null, i);
|
7 | }
|
8 | }, i);
|
9 | }
|
10 |
|
11 | var r = [];
|
12 | try {
|
13 | parallel(
|
14 | f(50, obtain(r[0])),
|
15 | f(100, obtain(r[1])),
|
16 | f(20, obtain(r[2])),
|
17 | f(10, obtain(r[3]))
|
18 | )
|
19 | } catch(err) {
|
20 | console.error(err);
|
21 | }
|
22 | console.log('Done');
|