async-rails 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dc696b7450ba8f34c9f3066b300a77660644356
4
- data.tar.gz: 07ece37305768c4e89d0891a0fafa0aad841b67d
3
+ metadata.gz: 182d41249e21ff33352c687668aab62d722ebc4c
4
+ data.tar.gz: 4e243ea2cdd11de19ea3daac44e018b97634e17d
5
5
  SHA512:
6
- metadata.gz: 9f0163a70f13e3bc1c9e70e9c0b599f0755c88e84250e92822fd4f39be66019154a5eb73cbc32a5da82e8e3b37e874f5aea6f2e67c55c9b41a99459e00e8eab1
7
- data.tar.gz: 011567913c47a220c909da89dfe8595855be4abd721db6dee5129a3e958477a10f03baafe9344e2b26a8537e04e3c401042a7264240281ef56d32848118b0755
6
+ metadata.gz: 977b93e88fa80d396da7d5d72d4882ae3931c15e33a9a8c5606d4ccf2c8e7fe98ee1ff3e8bfc2a0eb0aca5ff10759097f8b3a5c7eab56ebddc467699ea3a4901
7
+ data.tar.gz: 2249556a3161f2a70554f3270ff74543ffa312262d4c5eb37e06cdc4e1898ff59d072d85e60fee2bcd4e016ffdea4303849e6152a17263e8b5238cdc31ba89b9
@@ -1,5 +1,5 @@
1
1
  module Async
2
2
  module Rails
3
- VERSION = "0.5.0"
3
+ VERSION = "0.6.0"
4
4
  end
5
5
  end
@@ -481,6 +481,37 @@
481
481
  });
482
482
  };
483
483
 
484
+ async.retry = function(times, task, callback) {
485
+ var DEFAULT_TIMES = 5;
486
+ var attempts = [];
487
+ // Use defaults if times not passed
488
+ if (typeof times === 'function') {
489
+ callback = task;
490
+ task = times;
491
+ times = DEFAULT_TIMES;
492
+ }
493
+ // Make sure times is a number
494
+ times = parseInt(times, 10) || DEFAULT_TIMES;
495
+ var wrappedTask = function(wrappedCallback, wrappedResults) {
496
+ var retryAttempt = function(task, finalAttempt) {
497
+ return function(seriesCallback) {
498
+ task(function(err, result){
499
+ seriesCallback(!err || finalAttempt, {err: err, result: result});
500
+ }, wrappedResults);
501
+ };
502
+ };
503
+ while (times) {
504
+ attempts.push(retryAttempt(task, !(times-=1)));
505
+ }
506
+ async.series(attempts, function(done, data){
507
+ data = data[data.length - 1];
508
+ (wrappedCallback || callback)(data.err, data.result);
509
+ });
510
+ }
511
+ // If a callback is passed, run this as a controll flow
512
+ return callback ? wrappedTask() : wrappedTask
513
+ };
514
+
484
515
  async.waterfall = function (tasks, callback) {
485
516
  callback = callback || function () {};
486
517
  if (!_isArray(tasks)) {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: async-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Chen