async-rails 1.4.2 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80d7d4b07b2f5704f365a9fc1ec1ba5813d4589e
4
- data.tar.gz: 48cb6bbd0fb179c35dd3e462be438d93581dfd3a
3
+ metadata.gz: 09e26d9f69032f854510f8efddbea3abfd9744b6
4
+ data.tar.gz: 2298acd3231bd05ee92f3b8d88af96a4c7eec58e
5
5
  SHA512:
6
- metadata.gz: 998ce0d337d95276bb1d26be5c44ab5776dd22b84c1f4c545085ce72babba41bbb913357389a333f95cd7efaa0ecd2858fd45fbdbfa6fb5478f9b8301d64b62e
7
- data.tar.gz: 1f52a8f12300442eb86c9161fd0b0695b2505e770271413cb281e4e032d98219391b6fde9994a2e8d1ea2359105ab402d53b9d62b37cdf82b1bfe18b1cac8c52
6
+ metadata.gz: 9f8f8a95abeb5c53621d2f35ac904a83b86c1a47b600e8522d7679c437b9937733591fbd0413f55f7d4af9a1e00977742dbdacf8b65de687ede55fa15d84d8ef
7
+ data.tar.gz: 6e8cfc36beef4b9b5b713d7eac8ac43243fbcb58b834ed1399b61c3c1d6238c5a4f54bf759884c2ca54c099831685b7cd4bd9a3b8bf4e7285c58743d3280b9d1
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Rails
3
- VERSION = "1.4.2"
3
+ VERSION = "1.5.0"
4
4
  end
5
5
  end
@@ -77,12 +77,6 @@
77
77
  );
78
78
  }
79
79
 
80
- function _each(coll, iterator) {
81
- return _isArrayLike(coll) ?
82
- _arrayEach(coll, iterator) :
83
- _forEachOf(coll, iterator);
84
- }
85
-
86
80
  function _arrayEach(arr, iterator) {
87
81
  var index = -1,
88
82
  length = arr.length;
@@ -230,23 +224,26 @@
230
224
  async.eachOf = function (object, iterator, callback) {
231
225
  callback = _once(callback || noop);
232
226
  object = object || [];
233
- var size = _isArrayLike(object) ? object.length : _keys(object).length;
234
- var completed = 0;
235
- if (!size) {
236
- return callback(null);
237
- }
238
- _each(object, function (value, key) {
227
+
228
+ var iter = _keyIterator(object);
229
+ var key, completed = 0;
230
+
231
+ while ((key = iter()) != null) {
232
+ completed += 1;
239
233
  iterator(object[key], key, only_once(done));
240
- });
234
+ }
235
+
236
+ if (completed === 0) callback(null);
237
+
241
238
  function done(err) {
239
+ completed--;
242
240
  if (err) {
243
241
  callback(err);
244
242
  }
245
- else {
246
- completed += 1;
247
- if (completed >= size) {
248
- callback(null);
249
- }
243
+ // Check key is null in case iterator isn't exhausted
244
+ // and done resolved synchronously.
245
+ else if (key === null && completed <= 0) {
246
+ callback(null);
250
247
  }
251
248
  }
252
249
  };
@@ -272,7 +269,7 @@
272
269
  return callback(null);
273
270
  } else {
274
271
  if (sync) {
275
- async.nextTick(iterate);
272
+ async.setImmediate(iterate);
276
273
  } else {
277
274
  iterate();
278
275
  }
@@ -353,7 +350,8 @@
353
350
 
354
351
  function _asyncMap(eachfn, arr, iterator, callback) {
355
352
  callback = _once(callback || noop);
356
- var results = [];
353
+ arr = arr || [];
354
+ var results = _isArrayLike(arr) ? [] : {};
357
355
  eachfn(arr, function (value, index, callback) {
358
356
  iterator(value, function (err, v) {
359
357
  results[index] = v;
@@ -379,7 +377,7 @@
379
377
  callback(err);
380
378
  });
381
379
  }, function (err) {
382
- callback(err || null, memo);
380
+ callback(err, memo);
383
381
  });
384
382
  };
385
383
 
@@ -389,6 +387,20 @@
389
387
  async.reduce(reversed, memo, iterator, callback);
390
388
  };
391
389
 
390
+ async.transform = function (arr, memo, iterator, callback) {
391
+ if (arguments.length === 3) {
392
+ callback = iterator;
393
+ iterator = memo;
394
+ memo = _isArray(arr) ? [] : {};
395
+ }
396
+
397
+ async.eachOf(arr, function(v, k, cb) {
398
+ iterator(memo, v, k, cb);
399
+ }, function(err) {
400
+ callback(err, memo);
401
+ });
402
+ };
403
+
392
404
  function _filter(eachfn, arr, iterator, callback) {
393
405
  var results = [];
394
406
  eachfn(arr, function (x, index, callback) {
@@ -497,15 +509,24 @@
497
509
  }
498
510
  };
499
511
 
500
- async.auto = function (tasks, callback) {
512
+ async.auto = function (tasks, concurrency, callback) {
513
+ if (!callback) {
514
+ // concurrency is optional, shift the args.
515
+ callback = concurrency;
516
+ concurrency = null;
517
+ }
501
518
  callback = _once(callback || noop);
502
519
  var keys = _keys(tasks);
503
520
  var remainingTasks = keys.length;
504
521
  if (!remainingTasks) {
505
522
  return callback(null);
506
523
  }
524
+ if (!concurrency) {
525
+ concurrency = remainingTasks;
526
+ }
507
527
 
508
528
  var results = {};
529
+ var runningTasks = 0;
509
530
 
510
531
  var listeners = [];
511
532
  function addListener(fn) {
@@ -531,6 +552,7 @@
531
552
  _arrayEach(keys, function (k) {
532
553
  var task = _isArray(tasks[k]) ? tasks[k]: [tasks[k]];
533
554
  var taskCallback = _restParam(function(err, args) {
555
+ runningTasks--;
534
556
  if (args.length <= 1) {
535
557
  args = args[0];
536
558
  }
@@ -560,11 +582,12 @@
560
582
  }
561
583
  }
562
584
  function ready() {
563
- return _reduce(requires, function (a, x) {
585
+ return runningTasks < concurrency && _reduce(requires, function (a, x) {
564
586
  return (a && results.hasOwnProperty(x));
565
587
  }, true) && !results.hasOwnProperty(k);
566
588
  }
567
589
  if (ready()) {
590
+ runningTasks++;
568
591
  task[task.length - 1](taskCallback, results);
569
592
  }
570
593
  else {
@@ -572,6 +595,7 @@
572
595
  }
573
596
  function listener() {
574
597
  if (ready()) {
598
+ runningTasks++;
575
599
  removeListener(listener);
576
600
  task[task.length - 1](taskCallback, results);
577
601
  }
@@ -863,8 +887,17 @@
863
887
  function _next(q, tasks) {
864
888
  return function(){
865
889
  workers -= 1;
890
+
891
+ var removed = false;
866
892
  var args = arguments;
867
893
  _arrayEach(tasks, function (task) {
894
+ _arrayEach(workersList, function (worker, index) {
895
+ if (worker === task && !removed) {
896
+ workersList.splice(index, 1);
897
+ removed = true;
898
+ }
899
+ });
900
+
868
901
  task.callback.apply(task, args);
869
902
  });
870
903
  if (q.tasks.length + workers === 0) {
@@ -875,6 +908,7 @@
875
908
  }
876
909
 
877
910
  var workers = 0;
911
+ var workersList = [];
878
912
  var q = {
879
913
  tasks: [],
880
914
  concurrency: concurrency,
@@ -909,6 +943,7 @@
909
943
  q.empty();
910
944
  }
911
945
  workers += 1;
946
+ workersList.push(tasks[0]);
912
947
  var cb = only_once(_next(q, tasks));
913
948
  worker(data, cb);
914
949
  }
@@ -920,6 +955,9 @@
920
955
  running: function () {
921
956
  return workers;
922
957
  },
958
+ workersList: function () {
959
+ return workersList;
960
+ },
923
961
  idle: function() {
924
962
  return q.tasks.length + workers === 0;
925
963
  },
@@ -1048,7 +1086,7 @@
1048
1086
  var callback = args.pop();
1049
1087
  var key = hasher.apply(null, args);
1050
1088
  if (key in memo) {
1051
- async.nextTick(function () {
1089
+ async.setImmediate(function () {
1052
1090
  callback.apply(null, memo[key]);
1053
1091
  });
1054
1092
  }
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: 1.4.2
4
+ version: 1.5.0
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-09-04 00:00:00.000000000 Z
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties