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 +4 -4
- data/lib/async-rails/version.rb +1 -1
- data/vendor/assets/javascripts/async.js +31 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 182d41249e21ff33352c687668aab62d722ebc4c
|
4
|
+
data.tar.gz: 4e243ea2cdd11de19ea3daac44e018b97634e17d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 977b93e88fa80d396da7d5d72d4882ae3931c15e33a9a8c5606d4ccf2c8e7fe98ee1ff3e8bfc2a0eb0aca5ff10759097f8b3a5c7eab56ebddc467699ea3a4901
|
7
|
+
data.tar.gz: 2249556a3161f2a70554f3270ff74543ffa312262d4c5eb37e06cdc4e1898ff59d072d85e60fee2bcd4e016ffdea4303849e6152a17263e8b5238cdc31ba89b9
|
data/lib/async-rails/version.rb
CHANGED
@@ -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)) {
|