-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy patha-test.js
More file actions
50 lines (45 loc) · 1.23 KB
/
a-test.js
File metadata and controls
50 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
'use strict';
module.exports = (chaining, done) => {
let count = 0;
const next = () => (++count === 3 && done ? done() : 0);
chaining
.for([1, 2, 3, 4])
.filter((item) => item % 2 === 0)
.map((item) => item * 2)
.reduce((a, b) => a + b)
.fetch((err, result) => {
if (err) throw err;
if (!done) console.dir(result);
next();
});
chaining
.for([1, 2, 3, 4])
.filter((item, cb) => cb(null, item % 2 === 0))
.map((item, cb) => cb(null, item * 2))
.reduce((a, b, cb) => cb(null, a + b))
.fetch((err, result) => {
if (err) throw err;
if (!done) console.dir(result);
next();
});
chaining
.for([1, 2, 3, 4])
.filter((item, cb) => process.nextTick(cb, null, item % 2 === 0))
.map((item, cb) => process.nextTick(cb, null, item * 2))
.reduce((a, b, cb) => process.nextTick(cb, null, a + b))
.fetch((err, result) => {
if (err) throw err;
if (!done) console.dir(result);
next();
});
chaining
.for([1, 2, 3, 4])
.map((item, cb) => cb(new Error('Something happened')))
.fetch((err, result) => {
if (!done) {
if (err) console.log(err.message);
else console.dir(result);
}
next();
});
};