async-rails 0.9.2 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/async-rails/version.rb +1 -1
- data/vendor/assets/javascripts/async.js +251 -89
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f2f0d5008e172bd87a7dcea946cd29a2e0e9235
|
4
|
+
data.tar.gz: b52c5f238f50edd12bde0e5c1612b332bae398db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e99ba2afc03e64eec2378082145aefcd585e56b92d4118788f1c7541df60b0eb0b8605ce7ae62ca55a114934776a785d46cecb9645ba4168d9ea3211854fc475
|
7
|
+
data.tar.gz: 1b13b2f9dc0b83fe726162441e26d4d00491ca67c93d2298dc5df9d40278579477522032b3171ce020ba9a56d120bc34418c6a383fe439e318038f49a6c0cf07
|
data/lib/async-rails/version.rb
CHANGED
@@ -5,16 +5,24 @@
|
|
5
5
|
* Copyright 2010-2014 Caolan McMahon
|
6
6
|
* Released under the MIT license
|
7
7
|
*/
|
8
|
-
/*jshint onevar: false, indent:4 */
|
9
|
-
/*global setImmediate: false, setTimeout: false, console: false */
|
10
8
|
(function () {
|
11
9
|
|
12
10
|
var async = {};
|
11
|
+
var noop = function () {};
|
13
12
|
|
14
13
|
// global on the server, window in the browser
|
15
14
|
var root, previous_async;
|
16
15
|
|
17
|
-
|
16
|
+
if (typeof window == 'object' && this === window) {
|
17
|
+
root = window;
|
18
|
+
}
|
19
|
+
else if (typeof global == 'object' && this === global) {
|
20
|
+
root = global;
|
21
|
+
}
|
22
|
+
else {
|
23
|
+
root = this;
|
24
|
+
}
|
25
|
+
|
18
26
|
if (root != null) {
|
19
27
|
previous_async = root.async;
|
20
28
|
}
|
@@ -30,7 +38,7 @@
|
|
30
38
|
if (called) throw new Error("Callback was already called.");
|
31
39
|
called = true;
|
32
40
|
fn.apply(root, arguments);
|
33
|
-
}
|
41
|
+
};
|
34
42
|
}
|
35
43
|
|
36
44
|
//// cross-browser compatiblity functions ////
|
@@ -42,36 +50,39 @@
|
|
42
50
|
};
|
43
51
|
|
44
52
|
var _each = function (arr, iterator) {
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
var index = -1,
|
54
|
+
length = arr.length;
|
55
|
+
|
56
|
+
while (++index < length) {
|
57
|
+
iterator(arr[index], index, arr);
|
58
|
+
}
|
48
59
|
};
|
49
60
|
|
50
61
|
var _map = function (arr, iterator) {
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
var index = -1,
|
63
|
+
length = arr.length,
|
64
|
+
result = Array(length);
|
65
|
+
|
66
|
+
while (++index < length) {
|
67
|
+
result[index] = iterator(arr[index], index, arr);
|
68
|
+
}
|
69
|
+
return result;
|
59
70
|
};
|
60
71
|
|
61
72
|
var _reduce = function (arr, iterator, memo) {
|
62
|
-
if (arr.reduce) {
|
63
|
-
return arr.reduce(iterator, memo);
|
64
|
-
}
|
65
73
|
_each(arr, function (x, i, a) {
|
66
74
|
memo = iterator(memo, x, i, a);
|
67
75
|
});
|
68
76
|
return memo;
|
69
77
|
};
|
70
78
|
|
71
|
-
var
|
72
|
-
|
73
|
-
|
74
|
-
}
|
79
|
+
var _forEachOf = function (object, iterator) {
|
80
|
+
_each(_keys(object), function (key) {
|
81
|
+
iterator(object[key], key);
|
82
|
+
});
|
83
|
+
};
|
84
|
+
|
85
|
+
var _keys = Object.keys || function (obj) {
|
75
86
|
var keys = [];
|
76
87
|
for (var k in obj) {
|
77
88
|
if (obj.hasOwnProperty(k)) {
|
@@ -81,14 +92,38 @@
|
|
81
92
|
return keys;
|
82
93
|
};
|
83
94
|
|
95
|
+
var _baseSlice = function (arr, start) {
|
96
|
+
start = start || 0;
|
97
|
+
var index = -1;
|
98
|
+
var length = arr.length;
|
99
|
+
|
100
|
+
if (start) {
|
101
|
+
length -= start;
|
102
|
+
length = length < 0 ? 0 : length;
|
103
|
+
}
|
104
|
+
var result = Array(length);
|
105
|
+
|
106
|
+
while (++index < length) {
|
107
|
+
result[index] = arr[index + start];
|
108
|
+
}
|
109
|
+
return result;
|
110
|
+
};
|
111
|
+
|
84
112
|
//// exported async module functions ////
|
85
113
|
|
86
114
|
//// nextTick implementation with browser-compatible fallback ////
|
115
|
+
|
116
|
+
// capture the global reference to guard against fakeTimer mocks
|
117
|
+
var _setImmediate;
|
118
|
+
if (typeof setImmediate === 'function') {
|
119
|
+
_setImmediate = setImmediate;
|
120
|
+
}
|
121
|
+
|
87
122
|
if (typeof process === 'undefined' || !(process.nextTick)) {
|
88
|
-
if (
|
123
|
+
if (_setImmediate) {
|
89
124
|
async.nextTick = function (fn) {
|
90
125
|
// not a direct alias for IE10 compatibility
|
91
|
-
|
126
|
+
_setImmediate(fn);
|
92
127
|
};
|
93
128
|
async.setImmediate = async.nextTick;
|
94
129
|
}
|
@@ -101,10 +136,10 @@
|
|
101
136
|
}
|
102
137
|
else {
|
103
138
|
async.nextTick = process.nextTick;
|
104
|
-
if (
|
139
|
+
if (_setImmediate) {
|
105
140
|
async.setImmediate = function (fn) {
|
106
141
|
// not a direct alias for IE10 compatibility
|
107
|
-
|
142
|
+
_setImmediate(fn);
|
108
143
|
};
|
109
144
|
}
|
110
145
|
else {
|
@@ -113,9 +148,9 @@
|
|
113
148
|
}
|
114
149
|
|
115
150
|
async.each = function (arr, iterator, callback) {
|
116
|
-
callback = callback ||
|
151
|
+
callback = callback || noop;
|
117
152
|
if (!arr.length) {
|
118
|
-
return callback();
|
153
|
+
return callback(null);
|
119
154
|
}
|
120
155
|
var completed = 0;
|
121
156
|
_each(arr, function (x) {
|
@@ -124,12 +159,12 @@
|
|
124
159
|
function done(err) {
|
125
160
|
if (err) {
|
126
161
|
callback(err);
|
127
|
-
callback =
|
162
|
+
callback = noop;
|
128
163
|
}
|
129
164
|
else {
|
130
165
|
completed += 1;
|
131
166
|
if (completed >= arr.length) {
|
132
|
-
callback();
|
167
|
+
callback(null);
|
133
168
|
}
|
134
169
|
}
|
135
170
|
}
|
@@ -137,21 +172,21 @@
|
|
137
172
|
async.forEach = async.each;
|
138
173
|
|
139
174
|
async.eachSeries = function (arr, iterator, callback) {
|
140
|
-
callback = callback ||
|
175
|
+
callback = callback || noop;
|
141
176
|
if (!arr.length) {
|
142
|
-
return callback();
|
177
|
+
return callback(null);
|
143
178
|
}
|
144
179
|
var completed = 0;
|
145
180
|
var iterate = function () {
|
146
181
|
iterator(arr[completed], function (err) {
|
147
182
|
if (err) {
|
148
183
|
callback(err);
|
149
|
-
callback =
|
184
|
+
callback = noop;
|
150
185
|
}
|
151
186
|
else {
|
152
187
|
completed += 1;
|
153
188
|
if (completed >= arr.length) {
|
154
|
-
callback();
|
189
|
+
callback(null);
|
155
190
|
}
|
156
191
|
else {
|
157
192
|
iterate();
|
@@ -163,6 +198,7 @@
|
|
163
198
|
};
|
164
199
|
async.forEachSeries = async.eachSeries;
|
165
200
|
|
201
|
+
|
166
202
|
async.eachLimit = function (arr, limit, iterator, callback) {
|
167
203
|
var fn = _eachLimit(limit);
|
168
204
|
fn.apply(null, [arr, iterator, callback]);
|
@@ -172,32 +208,143 @@
|
|
172
208
|
var _eachLimit = function (limit) {
|
173
209
|
|
174
210
|
return function (arr, iterator, callback) {
|
175
|
-
callback = callback ||
|
211
|
+
callback = callback || noop;
|
176
212
|
if (!arr.length || limit <= 0) {
|
177
|
-
return callback();
|
213
|
+
return callback(null);
|
178
214
|
}
|
179
215
|
var completed = 0;
|
180
216
|
var started = 0;
|
181
217
|
var running = 0;
|
218
|
+
var errored = false;
|
182
219
|
|
183
220
|
(function replenish () {
|
184
221
|
if (completed >= arr.length) {
|
185
|
-
return callback();
|
222
|
+
return callback(null);
|
186
223
|
}
|
187
224
|
|
188
|
-
while (running < limit && started < arr.length) {
|
225
|
+
while (running < limit && started < arr.length && !errored) {
|
189
226
|
started += 1;
|
190
227
|
running += 1;
|
191
228
|
iterator(arr[started - 1], function (err) {
|
192
229
|
if (err) {
|
193
230
|
callback(err);
|
194
|
-
|
231
|
+
errored = true;
|
232
|
+
callback = noop;
|
195
233
|
}
|
196
234
|
else {
|
197
235
|
completed += 1;
|
198
236
|
running -= 1;
|
199
237
|
if (completed >= arr.length) {
|
200
|
-
callback();
|
238
|
+
callback(null);
|
239
|
+
}
|
240
|
+
else {
|
241
|
+
replenish();
|
242
|
+
}
|
243
|
+
}
|
244
|
+
});
|
245
|
+
}
|
246
|
+
})();
|
247
|
+
};
|
248
|
+
};
|
249
|
+
|
250
|
+
|
251
|
+
|
252
|
+
async.forEachOf = async.eachOf = function (object, iterator, callback) {
|
253
|
+
callback = callback || function () {};
|
254
|
+
var size = object.length || _keys(object).length;
|
255
|
+
var completed = 0;
|
256
|
+
if (!size) {
|
257
|
+
return callback(null);
|
258
|
+
}
|
259
|
+
_forEachOf(object, function (value, key) {
|
260
|
+
iterator(object[key], key, function (err) {
|
261
|
+
if (err) {
|
262
|
+
callback(err);
|
263
|
+
callback = function () {};
|
264
|
+
} else {
|
265
|
+
completed += 1;
|
266
|
+
if (completed === size) {
|
267
|
+
callback(null);
|
268
|
+
}
|
269
|
+
}
|
270
|
+
});
|
271
|
+
});
|
272
|
+
};
|
273
|
+
|
274
|
+
async.forEachOfSeries = async.eachOfSeries = function (obj, iterator, callback) {
|
275
|
+
callback = callback || function () {};
|
276
|
+
var keys = _keys(obj);
|
277
|
+
var size = keys.length;
|
278
|
+
if (!size) {
|
279
|
+
return callback();
|
280
|
+
}
|
281
|
+
var completed = 0;
|
282
|
+
var iterate = function () {
|
283
|
+
var sync = true;
|
284
|
+
var key = keys[completed];
|
285
|
+
iterator(obj[key], key, function (err) {
|
286
|
+
if (err) {
|
287
|
+
callback(err);
|
288
|
+
callback = function () {};
|
289
|
+
}
|
290
|
+
else {
|
291
|
+
completed += 1;
|
292
|
+
if (completed >= size) {
|
293
|
+
callback(null);
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
if (sync) {
|
297
|
+
async.nextTick(iterate);
|
298
|
+
}
|
299
|
+
else {
|
300
|
+
iterate();
|
301
|
+
}
|
302
|
+
}
|
303
|
+
}
|
304
|
+
});
|
305
|
+
sync = false;
|
306
|
+
};
|
307
|
+
iterate();
|
308
|
+
};
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
async.forEachOfLimit = async.eachOfLimit = function (obj, limit, iterator, callback) {
|
313
|
+
_forEachOfLimit(limit)(obj, iterator, callback);
|
314
|
+
};
|
315
|
+
|
316
|
+
var _forEachOfLimit = function (limit) {
|
317
|
+
|
318
|
+
return function (obj, iterator, callback) {
|
319
|
+
callback = callback || function () {};
|
320
|
+
var keys = _keys(obj);
|
321
|
+
var size = keys.length;
|
322
|
+
if (!size || limit <= 0) {
|
323
|
+
return callback(null);
|
324
|
+
}
|
325
|
+
var completed = 0;
|
326
|
+
var started = 0;
|
327
|
+
var running = 0;
|
328
|
+
|
329
|
+
(function replenish () {
|
330
|
+
if (completed >= size) {
|
331
|
+
return callback();
|
332
|
+
}
|
333
|
+
|
334
|
+
while (running < limit && started < size) {
|
335
|
+
started += 1;
|
336
|
+
running += 1;
|
337
|
+
var key = keys[started - 1];
|
338
|
+
iterator(obj[key], key, function (err) {
|
339
|
+
if (err) {
|
340
|
+
callback(err);
|
341
|
+
callback = function () {};
|
342
|
+
}
|
343
|
+
else {
|
344
|
+
completed += 1;
|
345
|
+
running -= 1;
|
346
|
+
if (completed >= size) {
|
347
|
+
callback(null);
|
201
348
|
}
|
202
349
|
else {
|
203
350
|
replenish();
|
@@ -212,19 +359,19 @@
|
|
212
359
|
|
213
360
|
var doParallel = function (fn) {
|
214
361
|
return function () {
|
215
|
-
var args =
|
362
|
+
var args = _baseSlice(arguments);
|
216
363
|
return fn.apply(null, [async.each].concat(args));
|
217
364
|
};
|
218
365
|
};
|
219
366
|
var doParallelLimit = function(limit, fn) {
|
220
367
|
return function () {
|
221
|
-
var args =
|
368
|
+
var args = _baseSlice(arguments);
|
222
369
|
return fn.apply(null, [_eachLimit(limit)].concat(args));
|
223
370
|
};
|
224
371
|
};
|
225
372
|
var doSeries = function (fn) {
|
226
373
|
return function () {
|
227
|
-
var args =
|
374
|
+
var args = _baseSlice(arguments);
|
228
375
|
return fn.apply(null, [async.eachSeries].concat(args));
|
229
376
|
};
|
230
377
|
};
|
@@ -271,7 +418,7 @@
|
|
271
418
|
callback(err);
|
272
419
|
});
|
273
420
|
}, function (err) {
|
274
|
-
callback(err, memo);
|
421
|
+
callback(err || null, memo);
|
275
422
|
});
|
276
423
|
};
|
277
424
|
// inject alias
|
@@ -342,7 +489,7 @@
|
|
342
489
|
iterator(x, function (result) {
|
343
490
|
if (result) {
|
344
491
|
main_callback(x);
|
345
|
-
main_callback =
|
492
|
+
main_callback = noop;
|
346
493
|
}
|
347
494
|
else {
|
348
495
|
callback();
|
@@ -360,7 +507,7 @@
|
|
360
507
|
iterator(x, function (v) {
|
361
508
|
if (v) {
|
362
509
|
main_callback(true);
|
363
|
-
main_callback =
|
510
|
+
main_callback = noop;
|
364
511
|
}
|
365
512
|
callback();
|
366
513
|
});
|
@@ -376,7 +523,7 @@
|
|
376
523
|
iterator(x, function (v) {
|
377
524
|
if (!v) {
|
378
525
|
main_callback(false);
|
379
|
-
main_callback =
|
526
|
+
main_callback = noop;
|
380
527
|
}
|
381
528
|
callback();
|
382
529
|
});
|
@@ -414,11 +561,11 @@
|
|
414
561
|
};
|
415
562
|
|
416
563
|
async.auto = function (tasks, callback) {
|
417
|
-
callback = callback ||
|
564
|
+
callback = callback || noop;
|
418
565
|
var keys = _keys(tasks);
|
419
|
-
var remainingTasks = keys.length
|
566
|
+
var remainingTasks = keys.length;
|
420
567
|
if (!remainingTasks) {
|
421
|
-
return callback();
|
568
|
+
return callback(null);
|
422
569
|
}
|
423
570
|
|
424
571
|
var results = {};
|
@@ -436,7 +583,7 @@
|
|
436
583
|
}
|
437
584
|
};
|
438
585
|
var taskComplete = function () {
|
439
|
-
remainingTasks
|
586
|
+
remainingTasks--;
|
440
587
|
_each(listeners.slice(0), function (fn) {
|
441
588
|
fn();
|
442
589
|
});
|
@@ -446,7 +593,7 @@
|
|
446
593
|
if (!remainingTasks) {
|
447
594
|
var theCallback = callback;
|
448
595
|
// prevent final callback from calling itself if it errors
|
449
|
-
callback =
|
596
|
+
callback = noop;
|
450
597
|
|
451
598
|
theCallback(null, results);
|
452
599
|
}
|
@@ -455,7 +602,7 @@
|
|
455
602
|
_each(keys, function (k) {
|
456
603
|
var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]];
|
457
604
|
var taskCallback = function (err) {
|
458
|
-
var args =
|
605
|
+
var args = _baseSlice(arguments, 1);
|
459
606
|
if (args.length <= 1) {
|
460
607
|
args = args[0];
|
461
608
|
}
|
@@ -467,7 +614,7 @@
|
|
467
614
|
safeResults[k] = args;
|
468
615
|
callback(err, safeResults);
|
469
616
|
// stop subsequent errors hitting callback multiple times
|
470
|
-
callback =
|
617
|
+
callback = noop;
|
471
618
|
}
|
472
619
|
else {
|
473
620
|
results[k] = args;
|
@@ -475,6 +622,17 @@
|
|
475
622
|
}
|
476
623
|
};
|
477
624
|
var requires = task.slice(0, Math.abs(task.length - 1)) || [];
|
625
|
+
// prevent dead-locks
|
626
|
+
var len = requires.length;
|
627
|
+
var dep;
|
628
|
+
while (len--) {
|
629
|
+
if (!(dep = tasks[requires[len]])) {
|
630
|
+
throw new Error('Has inexistant dependency');
|
631
|
+
}
|
632
|
+
if (_isArray(dep) && !!~dep.indexOf(k)) {
|
633
|
+
throw new Error('Has cyclic dependencies');
|
634
|
+
}
|
635
|
+
}
|
478
636
|
var ready = function () {
|
479
637
|
return _reduce(requires, function (a, x) {
|
480
638
|
return (a && results.hasOwnProperty(x));
|
@@ -521,13 +679,13 @@
|
|
521
679
|
data = data[data.length - 1];
|
522
680
|
(wrappedCallback || callback)(data.err, data.result);
|
523
681
|
});
|
524
|
-
}
|
682
|
+
};
|
525
683
|
// If a callback is passed, run this as a controll flow
|
526
|
-
return callback ? wrappedTask() : wrappedTask
|
684
|
+
return callback ? wrappedTask() : wrappedTask;
|
527
685
|
};
|
528
686
|
|
529
687
|
async.waterfall = function (tasks, callback) {
|
530
|
-
callback = callback ||
|
688
|
+
callback = callback || noop;
|
531
689
|
if (!_isArray(tasks)) {
|
532
690
|
var err = new Error('First argument to waterfall must be an array of functions');
|
533
691
|
return callback(err);
|
@@ -539,10 +697,10 @@
|
|
539
697
|
return function (err) {
|
540
698
|
if (err) {
|
541
699
|
callback.apply(null, arguments);
|
542
|
-
callback =
|
700
|
+
callback = noop;
|
543
701
|
}
|
544
702
|
else {
|
545
|
-
var args =
|
703
|
+
var args = _baseSlice(arguments, 1);
|
546
704
|
var next = iterator.next();
|
547
705
|
if (next) {
|
548
706
|
args.push(wrapIterator(next));
|
@@ -560,12 +718,12 @@
|
|
560
718
|
};
|
561
719
|
|
562
720
|
var _parallel = function(eachfn, tasks, callback) {
|
563
|
-
callback = callback ||
|
721
|
+
callback = callback || noop;
|
564
722
|
if (_isArray(tasks)) {
|
565
723
|
eachfn.map(tasks, function (fn, callback) {
|
566
724
|
if (fn) {
|
567
725
|
fn(function (err) {
|
568
|
-
var args =
|
726
|
+
var args = _baseSlice(arguments, 1);
|
569
727
|
if (args.length <= 1) {
|
570
728
|
args = args[0];
|
571
729
|
}
|
@@ -578,7 +736,7 @@
|
|
578
736
|
var results = {};
|
579
737
|
eachfn.each(_keys(tasks), function (k, callback) {
|
580
738
|
tasks[k](function (err) {
|
581
|
-
var args =
|
739
|
+
var args = _baseSlice(arguments, 1);
|
582
740
|
if (args.length <= 1) {
|
583
741
|
args = args[0];
|
584
742
|
}
|
@@ -600,12 +758,12 @@
|
|
600
758
|
};
|
601
759
|
|
602
760
|
async.series = function (tasks, callback) {
|
603
|
-
callback = callback ||
|
761
|
+
callback = callback || noop;
|
604
762
|
if (_isArray(tasks)) {
|
605
763
|
async.mapSeries(tasks, function (fn, callback) {
|
606
764
|
if (fn) {
|
607
765
|
fn(function (err) {
|
608
|
-
var args =
|
766
|
+
var args = _baseSlice(arguments, 1);
|
609
767
|
if (args.length <= 1) {
|
610
768
|
args = args[0];
|
611
769
|
}
|
@@ -618,7 +776,7 @@
|
|
618
776
|
var results = {};
|
619
777
|
async.eachSeries(_keys(tasks), function (k, callback) {
|
620
778
|
tasks[k](function (err) {
|
621
|
-
var args =
|
779
|
+
var args = _baseSlice(arguments, 1);
|
622
780
|
if (args.length <= 1) {
|
623
781
|
args = args[0];
|
624
782
|
}
|
@@ -648,10 +806,10 @@
|
|
648
806
|
};
|
649
807
|
|
650
808
|
async.apply = function (fn) {
|
651
|
-
var args =
|
809
|
+
var args = _baseSlice(arguments, 1);
|
652
810
|
return function () {
|
653
811
|
return fn.apply(
|
654
|
-
null, args.concat(
|
812
|
+
null, args.concat(_baseSlice(arguments))
|
655
813
|
);
|
656
814
|
};
|
657
815
|
};
|
@@ -680,7 +838,7 @@
|
|
680
838
|
});
|
681
839
|
}
|
682
840
|
else {
|
683
|
-
callback();
|
841
|
+
callback(null);
|
684
842
|
}
|
685
843
|
};
|
686
844
|
|
@@ -689,12 +847,12 @@
|
|
689
847
|
if (err) {
|
690
848
|
return callback(err);
|
691
849
|
}
|
692
|
-
var args =
|
850
|
+
var args = _baseSlice(arguments, 1);
|
693
851
|
if (test.apply(null, args)) {
|
694
852
|
async.doWhilst(iterator, test, callback);
|
695
853
|
}
|
696
854
|
else {
|
697
|
-
callback();
|
855
|
+
callback(null);
|
698
856
|
}
|
699
857
|
});
|
700
858
|
};
|
@@ -709,7 +867,7 @@
|
|
709
867
|
});
|
710
868
|
}
|
711
869
|
else {
|
712
|
-
callback();
|
870
|
+
callback(null);
|
713
871
|
}
|
714
872
|
};
|
715
873
|
|
@@ -718,12 +876,12 @@
|
|
718
876
|
if (err) {
|
719
877
|
return callback(err);
|
720
878
|
}
|
721
|
-
var args =
|
879
|
+
var args = _baseSlice(arguments, 1);
|
722
880
|
if (!test.apply(null, args)) {
|
723
881
|
async.doUntil(iterator, test, callback);
|
724
882
|
}
|
725
883
|
else {
|
726
|
-
callback();
|
884
|
+
callback(null);
|
727
885
|
}
|
728
886
|
});
|
729
887
|
};
|
@@ -732,6 +890,9 @@
|
|
732
890
|
if (concurrency === undefined) {
|
733
891
|
concurrency = 1;
|
734
892
|
}
|
893
|
+
else if(concurrency === 0) {
|
894
|
+
throw new Error('Concurrency must not be zero');
|
895
|
+
}
|
735
896
|
function _insert(q, data, pos, callback) {
|
736
897
|
if (!q.started){
|
737
898
|
q.started = true;
|
@@ -739,7 +900,7 @@
|
|
739
900
|
if (!_isArray(data)) {
|
740
901
|
data = [data];
|
741
902
|
}
|
742
|
-
if(data.length
|
903
|
+
if(data.length === 0) {
|
743
904
|
// call drain immediately if there are no tasks
|
744
905
|
return async.setImmediate(function() {
|
745
906
|
if (q.drain) {
|
@@ -822,9 +983,10 @@
|
|
822
983
|
resume: function () {
|
823
984
|
if (q.paused === false) { return; }
|
824
985
|
q.paused = false;
|
986
|
+
var resumeCount = Math.min(q.concurrency, q.tasks.length);
|
825
987
|
// Need to call q.process once per concurrent
|
826
988
|
// worker to preserve full concurrency after pause
|
827
|
-
for (var w = 1; w <=
|
989
|
+
for (var w = 1; w <= resumeCount; w++) {
|
828
990
|
async.setImmediate(q.process);
|
829
991
|
}
|
830
992
|
}
|
@@ -836,7 +998,7 @@
|
|
836
998
|
|
837
999
|
function _compareTasks(a, b){
|
838
1000
|
return a.priority - b.priority;
|
839
|
-
}
|
1001
|
+
}
|
840
1002
|
|
841
1003
|
function _binarySearch(sequence, item, compare) {
|
842
1004
|
var beg = -1,
|
@@ -859,7 +1021,7 @@
|
|
859
1021
|
if (!_isArray(data)) {
|
860
1022
|
data = [data];
|
861
1023
|
}
|
862
|
-
if(data.length
|
1024
|
+
if(data.length === 0) {
|
863
1025
|
// call drain immediately if there are no tasks
|
864
1026
|
return async.setImmediate(function() {
|
865
1027
|
if (q.drain) {
|
@@ -932,9 +1094,9 @@
|
|
932
1094
|
return;
|
933
1095
|
}
|
934
1096
|
|
935
|
-
var ts = typeof payload === 'number'
|
936
|
-
|
937
|
-
|
1097
|
+
var ts = typeof payload === 'number' ?
|
1098
|
+
tasks.splice(0, payload) :
|
1099
|
+
tasks.splice(0, tasks.length);
|
938
1100
|
|
939
1101
|
var ds = _map(ts, function (task) {
|
940
1102
|
return task.data;
|
@@ -967,9 +1129,9 @@
|
|
967
1129
|
|
968
1130
|
var _console_fn = function (name) {
|
969
1131
|
return function (fn) {
|
970
|
-
var args =
|
1132
|
+
var args = _baseSlice(arguments, 1);
|
971
1133
|
fn.apply(null, args.concat([function (err) {
|
972
|
-
var args =
|
1134
|
+
var args = _baseSlice(arguments, 1);
|
973
1135
|
if (typeof console !== 'undefined') {
|
974
1136
|
if (err) {
|
975
1137
|
if (console.error) {
|
@@ -998,7 +1160,7 @@
|
|
998
1160
|
return x;
|
999
1161
|
};
|
1000
1162
|
var memoized = function () {
|
1001
|
-
var args =
|
1163
|
+
var args = _baseSlice(arguments);
|
1002
1164
|
var callback = args.pop();
|
1003
1165
|
var key = hasher.apply(null, args);
|
1004
1166
|
if (key in memo) {
|
@@ -1012,7 +1174,7 @@
|
|
1012
1174
|
else {
|
1013
1175
|
queues[key] = [callback];
|
1014
1176
|
fn.apply(null, args.concat([function () {
|
1015
|
-
memo[key] = arguments;
|
1177
|
+
memo[key] = _baseSlice(arguments);
|
1016
1178
|
var q = queues[key];
|
1017
1179
|
delete queues[key];
|
1018
1180
|
for (var i = 0, l = q.length; i < l; i++) {
|
@@ -1052,14 +1214,14 @@
|
|
1052
1214
|
var fns = arguments;
|
1053
1215
|
return function () {
|
1054
1216
|
var that = this;
|
1055
|
-
var args =
|
1217
|
+
var args = _baseSlice(arguments);
|
1056
1218
|
var callback = args.pop();
|
1057
1219
|
async.reduce(fns, args, function (newargs, fn, cb) {
|
1058
1220
|
fn.apply(that, newargs.concat([function () {
|
1059
1221
|
var err = arguments[0];
|
1060
|
-
var nextargs =
|
1222
|
+
var nextargs = _baseSlice(arguments, 1);
|
1061
1223
|
cb(err, nextargs);
|
1062
|
-
}]))
|
1224
|
+
}]));
|
1063
1225
|
},
|
1064
1226
|
function (err, results) {
|
1065
1227
|
callback.apply(that, [err].concat(results));
|
@@ -1074,7 +1236,7 @@
|
|
1074
1236
|
var _applyEach = function (eachfn, fns /*args...*/) {
|
1075
1237
|
var go = function () {
|
1076
1238
|
var that = this;
|
1077
|
-
var args =
|
1239
|
+
var args = _baseSlice(arguments);
|
1078
1240
|
var callback = args.pop();
|
1079
1241
|
return eachfn(fns, function (fn, cb) {
|
1080
1242
|
fn.apply(that, args.concat([cb]));
|
@@ -1082,7 +1244,7 @@
|
|
1082
1244
|
callback);
|
1083
1245
|
};
|
1084
1246
|
if (arguments.length > 2) {
|
1085
|
-
var args =
|
1247
|
+
var args = _baseSlice(arguments, 2);
|
1086
1248
|
return go.apply(this, args);
|
1087
1249
|
}
|
1088
1250
|
else {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Chen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|