async-rails 1.2.1 → 1.3.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: 822e1710db0d48af7875e4016a088156e1ddf25f
4
- data.tar.gz: 4929f3c3cf518c32f40851d6335b2ebf309b8222
3
+ metadata.gz: 2d28e11df0279381c8d0e03b6a2f51ecf9253846
4
+ data.tar.gz: e2e6a3d8e860fdab23ae6534d7700e56f670a7a0
5
5
  SHA512:
6
- metadata.gz: f935524ce99da416f64e644835d58ca856a0f37baf34929225cbd3317d78654bee81521991676f65cbfd12f04dbecb9ad5885f31b32ee6208dcebd38811c4ab0
7
- data.tar.gz: e1224528c9bb7104c101f930d52e6d156149ddf471df51dd8fc659fd3d69e322ea8f78333653ba6b7d2fa4bf0661ce95ae1588ad9cd84b9f04b47d075a63bf10
6
+ metadata.gz: 053811083f01269722e23d9f066d2d4846aa0ef8474717361f3d09b55fcb344614db1096792cce018b86bfe7b65df2302940861d351bbcfbc0e86a03ff45cc3b
7
+ data.tar.gz: 8606494455f7a21cf80951e24c9e280aa1a500c003382282e78e15d41518a77bc978ca66d32e4eca9c017d6796bdac03a0fb8d291a1da71a3cd3626585165e57
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Rails
3
- VERSION = "1.2.1"
3
+ VERSION = "1.3.0"
4
4
  end
5
5
  end
@@ -11,20 +11,17 @@
11
11
  function noop() {}
12
12
 
13
13
  // global on the server, window in the browser
14
- var root, previous_async;
14
+ var previous_async;
15
15
 
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
- }
16
+ // Establish the root object, `window` (`self`) in the browser, `global`
17
+ // on the server, or `this` in some virtual machines. We use `self`
18
+ // instead of `window` for `WebWorker` support.
19
+ var root = typeof self === 'object' && self.self === self && self ||
20
+ typeof global === 'object' && global.global === global && global ||
21
+ this;
25
22
 
26
23
  if (root != null) {
27
- previous_async = root.async;
24
+ previous_async = root.async;
28
25
  }
29
26
 
30
27
  async.noConflict = function () {
@@ -74,23 +71,23 @@
74
71
  }
75
72
 
76
73
  function _arrayEach(arr, iterator) {
77
- var index = -1,
78
- length = arr.length;
74
+ var index = -1,
75
+ length = arr.length;
79
76
 
80
- while (++index < length) {
81
- iterator(arr[index], index, arr);
82
- }
77
+ while (++index < length) {
78
+ iterator(arr[index], index, arr);
79
+ }
83
80
  }
84
81
 
85
82
  function _map(arr, iterator) {
86
- var index = -1,
87
- length = arr.length,
88
- result = Array(length);
89
-
90
- while (++index < length) {
91
- result[index] = iterator(arr[index], index, arr);
92
- }
93
- return result;
83
+ var index = -1,
84
+ length = arr.length,
85
+ result = Array(length);
86
+
87
+ while (++index < length) {
88
+ result[index] = iterator(arr[index], index, arr);
89
+ }
90
+ return result;
94
91
  }
95
92
 
96
93
  function _range(count) {
@@ -146,13 +143,13 @@
146
143
  var length = arr.length;
147
144
 
148
145
  if (start) {
149
- length -= start;
150
- length = length < 0 ? 0 : length;
146
+ length -= start;
147
+ length = length < 0 ? 0 : length;
151
148
  }
152
149
  var result = Array(length);
153
150
 
154
151
  while (++index < length) {
155
- result[index] = arr[index + start];
152
+ result[index] = arr[index + start];
156
153
  }
157
154
  return result;
158
155
  }
@@ -193,7 +190,7 @@
193
190
  if (_setImmediate) {
194
191
  async.setImmediate = function (fn) {
195
192
  // not a direct alias for IE10 compatibility
196
- _setImmediate(fn);
193
+ _setImmediate(fn);
197
194
  };
198
195
  }
199
196
  else {
@@ -230,15 +227,15 @@
230
227
  iterator(object[key], key, only_once(done));
231
228
  });
232
229
  function done(err) {
233
- if (err) {
234
- callback(err);
235
- }
236
- else {
237
- completed += 1;
238
- if (completed >= size) {
239
- callback(null);
240
- }
241
- }
230
+ if (err) {
231
+ callback(err);
232
+ }
233
+ else {
234
+ completed += 1;
235
+ if (completed >= size) {
236
+ callback(null);
237
+ }
238
+ }
242
239
  }
243
240
  };
244
241
 
@@ -416,24 +413,11 @@
416
413
  async.filterSeries = doSeries(_filter);
417
414
 
418
415
  function _reject(eachfn, arr, iterator, callback) {
419
- var results = [];
420
- arr = _map(arr, function (x, i) {
421
- return {index: i, value: x};
422
- });
423
- eachfn(arr, function (x, index, callback) {
424
- iterator(x.value, function (v) {
425
- if (!v) {
426
- results.push(x);
427
- }
428
- callback();
416
+ _filter(eachfn, arr, function(value, cb) {
417
+ iterator(value, function(v) {
418
+ cb(!v);
429
419
  });
430
- }, function () {
431
- callback(_map(results.sort(function (a, b) {
432
- return a.index - b.index;
433
- }), function (x) {
434
- return x.value;
435
- }));
436
- });
420
+ }, callback);
437
421
  }
438
422
  async.reject = doParallel(_reject);
439
423
  async.rejectSeries = doSeries(_reject);
@@ -601,17 +585,55 @@
601
585
  });
602
586
  };
603
587
 
604
- async.retry = function(times, task, callback) {
588
+
589
+
590
+ async.retry = function(/*[times,] task [, callback]*/) {
605
591
  var DEFAULT_TIMES = 5;
592
+ var DEFAULT_INTERVAL = 0;
593
+
606
594
  var attempts = [];
607
- // Use defaults if times not passed
608
- if (typeof times === 'function') {
609
- callback = task;
610
- task = times;
611
- times = DEFAULT_TIMES;
595
+
596
+ var opts = {
597
+ times: DEFAULT_TIMES,
598
+ interval: DEFAULT_INTERVAL
599
+ };
600
+
601
+ function parseTimes(acc, t){
602
+ if(typeof t === 'number'){
603
+ acc.times = parseInt(t, 10) || DEFAULT_TIMES;
604
+ } else if(typeof t === 'object'){
605
+ acc.times = parseInt(t.times, 10) || DEFAULT_TIMES;
606
+ acc.interval = parseInt(t.interval, 10) || DEFAULT_INTERVAL;
607
+ } else {
608
+ throw new Error('Unsupported argument type for \'times\': ' + typeof(t));
609
+ }
612
610
  }
613
- // Make sure times is a number
614
- times = parseInt(times, 10) || DEFAULT_TIMES;
611
+
612
+ switch(arguments.length){
613
+ case 1: {
614
+ opts.task = arguments[0];
615
+ break;
616
+ }
617
+ case 2 : {
618
+ if(typeof arguments[0] === 'number' || typeof arguments[0] === 'object'){
619
+ parseTimes(opts, arguments[0]);
620
+ opts.task = arguments[1];
621
+ } else {
622
+ opts.task = arguments[0];
623
+ opts.callback = arguments[1];
624
+ }
625
+ break;
626
+ }
627
+ case 3: {
628
+ parseTimes(opts, arguments[0]);
629
+ opts.task = arguments[1];
630
+ opts.callback = arguments[2];
631
+ break;
632
+ }
633
+ default: {
634
+ throw new Error('Invalid arguments - must be either (task), (task, callback), (times, task) or (times, task, callback)');
635
+ }
636
+ }
615
637
 
616
638
  function wrappedTask(wrappedCallback, wrappedResults) {
617
639
  function retryAttempt(task, finalAttempt) {
@@ -622,24 +644,38 @@
622
644
  };
623
645
  }
624
646
 
625
- while (times) {
626
- attempts.push(retryAttempt(task, !(times-=1)));
647
+ function retryInterval(interval){
648
+ return function(seriesCallback){
649
+ setTimeout(function(){
650
+ seriesCallback(null);
651
+ }, interval);
652
+ };
627
653
  }
654
+
655
+ while (opts.times) {
656
+
657
+ var finalAttempt = !(opts.times-=1);
658
+ attempts.push(retryAttempt(opts.task, finalAttempt));
659
+ if(!finalAttempt && opts.interval > 0){
660
+ attempts.push(retryInterval(opts.interval));
661
+ }
662
+ }
663
+
628
664
  async.series(attempts, function(done, data){
629
665
  data = data[data.length - 1];
630
- (wrappedCallback || callback)(data.err, data.result);
666
+ (wrappedCallback || opts.callback)(data.err, data.result);
631
667
  });
632
668
  }
633
669
 
634
670
  // If a callback is passed, run this as a controll flow
635
- return callback ? wrappedTask() : wrappedTask;
671
+ return opts.callback ? wrappedTask() : wrappedTask;
636
672
  };
637
673
 
638
674
  async.waterfall = function (tasks, callback) {
639
675
  callback = _once(callback || noop);
640
676
  if (!_isArray(tasks)) {
641
- var err = new Error('First argument to waterfall must be an array of functions');
642
- return callback(err);
677
+ var err = new Error('First argument to waterfall must be an array of functions');
678
+ return callback(err);
643
679
  }
644
680
  if (!tasks.length) {
645
681
  return callback();
@@ -749,6 +785,7 @@
749
785
  async.concatSeries = doSeries(_concat);
750
786
 
751
787
  async.whilst = function (test, iterator, callback) {
788
+ callback = callback || noop;
752
789
  if (test()) {
753
790
  iterator(function (err) {
754
791
  if (err) {
@@ -763,6 +800,7 @@
763
800
  };
764
801
 
765
802
  async.doWhilst = function (iterator, test, callback) {
803
+ callback = callback || noop;
766
804
  iterator(function (err) {
767
805
  if (err) {
768
806
  return callback(err);
@@ -778,6 +816,7 @@
778
816
  };
779
817
 
780
818
  async.until = function (test, iterator, callback) {
819
+ callback = callback || noop;
781
820
  if (!test()) {
782
821
  iterator(function (err) {
783
822
  if (err) {
@@ -792,6 +831,7 @@
792
831
  };
793
832
 
794
833
  async.doUntil = function (iterator, test, callback) {
834
+ callback = callback || noop;
795
835
  iterator(function (err) {
796
836
  if (err) {
797
837
  return callback(err);
@@ -806,6 +846,48 @@
806
846
  });
807
847
  };
808
848
 
849
+ async.during = function (test, iterator, callback) {
850
+ callback = callback || noop;
851
+ test(function(err, truth) {
852
+ if (err) {
853
+ return callback(err);
854
+ }
855
+ if (truth) {
856
+ iterator(function (err) {
857
+ if (err) {
858
+ return callback(err);
859
+ }
860
+ async.during(test, iterator, callback);
861
+ });
862
+ }
863
+ else {
864
+ callback(null);
865
+ }
866
+ });
867
+ };
868
+
869
+ async.doDuring = function (iterator, test, callback) {
870
+ callback = callback || noop;
871
+ iterator(function (err) {
872
+ if (err) {
873
+ return callback(err);
874
+ }
875
+ var args = _baseSlice(arguments, 1);
876
+ args.push(function (err, truth) {
877
+ if (err) {
878
+ return callback(err);
879
+ }
880
+ if (truth) {
881
+ async.doDuring(iterator, test, callback);
882
+ }
883
+ else {
884
+ callback(null);
885
+ }
886
+ });
887
+ test.apply(null, args);
888
+ });
889
+ };
890
+
809
891
  function _queue(worker, concurrency, payload) {
810
892
  if (concurrency == null) {
811
893
  concurrency = 1;
@@ -834,9 +916,9 @@
834
916
  };
835
917
 
836
918
  if (pos) {
837
- q.tasks.unshift(item);
919
+ q.tasks.unshift(item);
838
920
  } else {
839
- q.tasks.push(item);
921
+ q.tasks.push(item);
840
922
  }
841
923
 
842
924
  if (q.tasks.length === q.concurrency) {
@@ -863,6 +945,7 @@
863
945
  var q = {
864
946
  tasks: [],
865
947
  concurrency: concurrency,
948
+ payload: payload,
866
949
  saturated: noop,
867
950
  empty: noop,
868
951
  drain: noop,
@@ -881,8 +964,8 @@
881
964
  process: function () {
882
965
  if (!q.paused && workers < q.concurrency && q.tasks.length) {
883
966
  while(workers < q.concurrency && q.tasks.length){
884
- var tasks = payload ?
885
- q.tasks.splice(0, payload) :
967
+ var tasks = q.payload ?
968
+ q.tasks.splice(0, q.payload) :
886
969
  q.tasks.splice(0, q.tasks.length);
887
970
 
888
971
  var data = _map(tasks, function (task) {
@@ -1062,9 +1145,9 @@
1062
1145
  };
1063
1146
 
1064
1147
  async.unmemoize = function (fn) {
1065
- return function () {
1066
- return (fn.unmemoized || fn).apply(null, arguments);
1067
- };
1148
+ return function () {
1149
+ return (fn.unmemoized || fn).apply(null, arguments);
1150
+ };
1068
1151
  };
1069
1152
 
1070
1153
  function _times(mapper) {
@@ -1106,7 +1189,7 @@
1106
1189
  };
1107
1190
 
1108
1191
  async.compose = function (/* functions... */) {
1109
- return async.seq.apply(null, Array.prototype.reverse.call(arguments));
1192
+ return async.seq.apply(null, Array.prototype.reverse.call(arguments));
1110
1193
  };
1111
1194
 
1112
1195
 
@@ -1173,6 +1256,28 @@
1173
1256
 
1174
1257
  async.ensureAsync = ensureAsync;
1175
1258
 
1259
+ async.constant = function constant(/*values...*/) {
1260
+ var args = [null].concat(_baseSlice(arguments));
1261
+ return function (callback) {
1262
+ return callback.apply(this, args);
1263
+ };
1264
+ };
1265
+
1266
+ async.wrapSync =
1267
+ async.asyncify = function asyncify(func) {
1268
+ return function (/*args..., callback*/) {
1269
+ var args = _baseSlice(arguments);
1270
+ var callback = args.pop();
1271
+ var result;
1272
+ try {
1273
+ result = func.apply(this, args);
1274
+ } catch (e) {
1275
+ return callback(e);
1276
+ }
1277
+ callback(null, result);
1278
+ };
1279
+ };
1280
+
1176
1281
  // Node.js
1177
1282
  if (typeof module !== 'undefined' && module.exports) {
1178
1283
  module.exports = async;
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.2.1
4
+ version: 1.3.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-06-08 00:00:00.000000000 Z
11
+ date: 2015-07-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties