This repository was archived by the owner on Nov 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbound_async.js
More file actions
58 lines (47 loc) · 2.32 KB
/
bound_async.js
File metadata and controls
58 lines (47 loc) · 2.32 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
51
52
53
54
55
56
57
58
// provides a set of functions wrapping some common functions from the async module
// afford the patters of specifying iterator functions without having to explicitly
// bind everything to the calling context, at the expense of a single this argument
'use strict';
let Async = require('async');
module.exports = {
series (context, series, callback = null, bindCallback = false) {
let boundSeries = series.map(fn => fn.bind(context));
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.series(boundSeries, boundCallback);
},
parallel (context, parallel, callback = null, bindCallback = false) {
let boundParallel = parallel.map(fn => fn.bind(context));
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.parallel(boundParallel, boundCallback);
},
forEach (context, array, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.forEach(array, boundIterator, boundCallback);
},
forEachSeries (context, array, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.forEachSeries(array, boundIterator, boundCallback);
},
forEachLimit (context, array, limit, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.forEachLimit(array, limit, boundIterator, boundCallback);
},
whilst (context, condition, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.whilst(condition, boundIterator, boundCallback);
},
times (context, n, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.times(n, boundIterator, boundCallback);
},
timesSeries (context, n, iterator, callback = null, bindCallback = false) {
let boundIterator = iterator.bind(context);
let boundCallback = bindCallback ? callback.bind(context) : callback;
Async.timesSeries(n, boundIterator, boundCallback);
}
};