-
-
Notifications
You must be signed in to change notification settings - Fork 809
/
Copy pathrepl.txt
152 lines (124 loc) · 4.12 KB
/
repl.txt
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
{{alias}}( fcn, n, [options,] done )
Invokes a function `n` times and returns an array of accumulated function
return values.
For each iteration, the provided function is invoked with two arguments:
- `index`: invocation index (starting from zero)
- `next`: callback to be invoked upon function completion
The `next` callback accepts two arguments:
- `error`: error argument
- `result`: function result
If a provided function calls the `next` callback with a truthy `error`
argument, the function suspends execution and immediately calls the `done`
callback for subsequent `error` handling.
Execution is *not* guaranteed to be asynchronous. To guarantee asynchrony,
wrap the `done` callback in a function which either executes at the end of
the current stack (e.g., `nextTick`) or during a subsequent turn of the
event loop (e.g., `setImmediate`, `setTimeout`).
Parameters
----------
fcn: Function
Function to invoke.
n: integer
Number of times to invoke a function.
options: Object (optional)
Function options.
options.limit: integer (optional)
Maximum number of pending invocations. Default: Infinity.
options.series: boolean (optional)
Boolean indicating whether to allow only one pending invocation at a
time. Default: false.
options.thisArg: any (optional)
Execution context.
done: Function
A callback invoked upon executing a provided function `n` times or upon
encountering an error.
Examples
--------
// Basic usage:
> function fcn( i, next ) {
... setTimeout( onTimeout, 0 );
... function onTimeout() {
... next( null, i );
... }
... };
> function done( error, arr ) {
... if ( error ) {
... throw error;
... }
... console.log( arr );
... };
> {{alias}}( fcn, 10, done )
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
// Limit number of concurrent invocations:
> function fcn( i, next ) {
... setTimeout( onTimeout, 0 );
... function onTimeout() {
... next( null, i );
... }
... };
> function done( error, arr ) {
... if ( error ) {
... throw error;
... }
... console.log( arr );
... };
> var opts = { 'limit': 2 };
> {{alias}}( fcn, 10, opts, done )
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
// Sequential invocation:
> function fcn( i, next ) {
... setTimeout( onTimeout, 0 );
... function onTimeout() {
... next( null, i );
... }
... };
> function done( error, arr ) {
... if ( error ) {
... throw error;
... }
... console.log( arr );
... };
> var opts = { 'series': true };
> {{alias}}( fcn, 10, opts, done )
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
{{alias}}.factory( [options,] fcn )
Returns a function which invokes a function `n` times and returns an array
of accumulated function return values.
Parameters
----------
options: Object (optional)
Function options.
options.limit: integer (optional)
Maximum number of pending invocations. Default: Infinity.
options.series: boolean (optional)
Boolean indicating whether to allow only one pending invocation at a
time. Default: false.
options.thisArg: any (optional)
Execution context.
fcn: Function
Function to invoke.
Returns
-------
out: Function
A function which invokes a function `n` times and returns an array of
accumulated function return values.
Examples
--------
> function fcn( i, next ) {
... setTimeout( onTimeout, 0 );
... function onTimeout() {
... next( null, i );
... }
... };
> var opts = { 'series': true };
> var f = {{alias}}.factory( opts, fcn );
> function done( error, arr ) {
... if ( error ) {
... throw error;
... }
... console.log( arr );
... };
> f( 10, done )
[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
See Also
--------