Skip to content

Commit 190c9a7

Browse files
committed
Update built files
1 parent 6a7fa4e commit 190c9a7

3 files changed

Lines changed: 78 additions & 39 deletions

File tree

dist/async.js

Lines changed: 76 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -866,23 +866,25 @@
866866
/**
867867
* Applies the provided arguments to each function in the array, calling
868868
* `callback` after all functions have completed. If you only provide the first
869-
* argument, then it will return a function which lets you pass in the
870-
* arguments as if it were a single function call.
869+
* argument, `fns`, then it will return a function which lets you pass in the
870+
* arguments as if it were a single function call. If more arguments are
871+
* provided, `callback` is required while `args` is still optional.
871872
*
872873
* @name applyEach
873874
* @static
874875
* @memberOf module:ControlFlow
875876
* @method
876877
* @category Control Flow
877-
* @param {Array|Iterable|Object} fns - A collection of asynchronous functions to all
878-
* call with the same arguments
878+
* @param {Array|Iterable|Object} fns - A collection of asynchronous functions
879+
* to all call with the same arguments
879880
* @param {...*} [args] - any number of separate arguments to pass to the
880881
* function.
881882
* @param {Function} [callback] - the final argument should be the callback,
882883
* called when all functions have completed processing.
883-
* @returns {Function} - If only the first argument is provided, it will return
884-
* a function which lets you pass in the arguments as if it were a single
885-
* function call.
884+
* @returns {Function} - If only the first argument, `fns`, is provided, it will
885+
* return a function which lets you pass in the arguments as if it were a single
886+
* function call. The signature is `(..args, callback)`. If invoked with any
887+
* arguments, `callback` is required.
886888
* @example
887889
*
888890
* async.applyEach([enableSearch, updateSchema], 'bucket', callback);
@@ -1984,9 +1986,10 @@
19841986
q.drain();
19851987
});
19861988
}
1987-
arrayEach(data, function (task) {
1989+
1990+
for (var i = 0, l = data.length; i < l; i++) {
19881991
var item = {
1989-
data: task,
1992+
data: data[i],
19901993
callback: callback || noop
19911994
};
19921995

@@ -1995,28 +1998,27 @@
19951998
} else {
19961999
q._tasks.push(item);
19972000
}
1998-
});
2001+
}
19992002
setImmediate$1(q.process);
20002003
}
20012004

20022005
function _next(tasks) {
20032006
return baseRest(function (args) {
20042007
workers -= 1;
20052008

2006-
arrayEach(tasks, function (task) {
2007-
arrayEach(workersList, function (worker, index) {
2008-
if (worker === task) {
2009-
workersList.splice(index, 1);
2010-
return false;
2011-
}
2012-
});
2009+
for (var i = 0, l = tasks.length; i < l; i++) {
2010+
var task = tasks[i];
2011+
var index = baseIndexOf(workersList, task, 0);
2012+
if (index >= 0) {
2013+
workersList.splice(index);
2014+
}
20132015

20142016
task.callback.apply(task, args);
20152017

20162018
if (args[0] != null) {
20172019
q.error(args[0], task.data);
20182020
}
2019-
});
2021+
}
20202022

20212023
if (workers <= q.concurrency - q.buffer) {
20222024
q.unsaturated();
@@ -2728,8 +2730,8 @@
27282730
* passes. The function is passed a `callback(err)`, which must be called once
27292731
* it has completed with an optional `err` argument. Invoked with (callback).
27302732
* @param {Function} test - synchronous truth test to perform after each
2731-
* execution of `iteratee`. Invoked with Invoked with the non-error callback
2732-
* results of `iteratee`.
2733+
* execution of `iteratee`. Invoked with the non-error callback results of
2734+
* `iteratee`.
27332735
* @param {Function} [callback] - A callback which is called after the test
27342736
* function has failed and repeated execution of `iteratee` has stopped.
27352737
* `callback` will be passed an error and any arguments passed to the final
@@ -2904,7 +2906,7 @@
29042906
* @see [async.each]{@link module:Collections.each}
29052907
* @alias forEachLimit
29062908
* @category Collection
2907-
* @param {Array|Iterable|Object} coll - A colleciton to iterate over.
2909+
* @param {Array|Iterable|Object} coll - A collection to iterate over.
29082910
* @param {number} limit - The maximum number of async operations at a time.
29092911
* @param {Function} iteratee - A function to apply to each item in `coll`. The
29102912
* iteratee is passed a `callback(err)` which must be called once it has
@@ -3714,9 +3716,9 @@
37143716
nextNode = nextNode.next;
37153717
}
37163718

3717-
arrayEach(data, function (task) {
3719+
for (var i = 0, l = data.length; i < l; i++) {
37183720
var item = {
3719-
data: task,
3721+
data: data[i],
37203722
priority: priority,
37213723
callback: callback
37223724
};
@@ -3726,7 +3728,7 @@
37263728
} else {
37273729
q._tasks.push(item);
37283730
}
3729-
});
3731+
}
37303732
setImmediate$1(q.process);
37313733
};
37323734

@@ -3738,7 +3740,7 @@
37383740

37393741
/**
37403742
* Runs the `tasks` array of functions in parallel, without waiting until the
3741-
* previous function has completed. Once any the `tasks` completed or pass an
3743+
* previous function has completed. Once any of the `tasks` complete or pass an
37423744
* error to its callback, the main `callback` is immediately called. It's
37433745
* equivalent to `Promise.race()`.
37443746
*
@@ -3777,9 +3779,9 @@
37773779
callback = once(callback || noop);
37783780
if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
37793781
if (!tasks.length) return callback();
3780-
arrayEach(tasks, function (task) {
3781-
task(callback);
3782-
});
3782+
for (var i = 0, l = tasks.length; i < l; i++) {
3783+
tasks[i](callback);
3784+
}
37833785
}
37843786

37853787
var slice = Array.prototype.slice;
@@ -4074,6 +4076,11 @@
40744076
* * `interval` - The time to wait between retries, in milliseconds. The
40754077
* default is `0`. The interval may also be specified as a function of the
40764078
* retry count (see example).
4079+
* * `errorFilter` - An optional synchronous function that is invoked on
4080+
* erroneous result. If it returns `true` the retry attempts will continue;
4081+
* if the function returns `false` the retry flow is aborted with the current
4082+
* attempt's error and result being returned to the final callback.
4083+
* Invoked with (err).
40774084
* * If `opts` is a number, the number specifies the number of times to retry,
40784085
* with the default interval of `0`.
40794086
* @param {Function} task - A function which receives two arguments: (1) a
@@ -4117,6 +4124,16 @@
41174124
* // do something with the result
41184125
* });
41194126
*
4127+
* // try calling apiMethod only when error condition satisfies, all other
4128+
* // errors will abort the retry control flow and return to final callback
4129+
* async.retry({
4130+
* errorFilter: function(err) {
4131+
* return err.message === 'Temporary error'; // only retry on a specific error
4132+
* }
4133+
* }, apiMethod, function(err, result) {
4134+
* // do something with the result
4135+
* });
4136+
*
41204137
* // It can also be embedded within other control flow functions to retry
41214138
* // individual methods that are not as reliable, like this:
41224139
* async.auto({
@@ -4125,6 +4142,7 @@
41254142
* }, function(err, results) {
41264143
* // do something with the results
41274144
* });
4145+
*
41284146
*/
41294147
function retry(opts, task, callback) {
41304148
var DEFAULT_TIMES = 5;
@@ -4140,6 +4158,8 @@
41404158
acc.times = +t.times || DEFAULT_TIMES;
41414159

41424160
acc.intervalFunc = typeof t.interval === 'function' ? t.interval : constant$1(+t.interval || DEFAULT_INTERVAL);
4161+
4162+
acc.errorFilter = t.errorFilter;
41434163
} else if (typeof t === 'number' || typeof t === 'string') {
41444164
acc.times = +t || DEFAULT_TIMES;
41454165
} else {
@@ -4162,7 +4182,7 @@
41624182
var attempt = 1;
41634183
function retryAttempt() {
41644184
task(function (err) {
4165-
if (err && attempt++ < options.times) {
4185+
if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) {
41664186
setTimeout(retryAttempt, options.intervalFunc(attempt));
41674187
} else {
41684188
callback.apply(null, arguments);
@@ -4436,12 +4456,31 @@
44364456
* @param {*} [info] - Any variable you want attached (`string`, `object`, etc)
44374457
* to timeout Error for more information..
44384458
* @returns {Function} Returns a wrapped function that can be used with any of
4439-
* the control flow functions.
4459+
* the control flow functions. Invoke this function with the same
4460+
* parameters as you would `asyncFunc`.
44404461
* @example
44414462
*
4442-
* async.timeout(function(callback) {
4443-
* doAsyncTask(callback);
4444-
* }, 1000);
4463+
* function myFunction(foo, callback) {
4464+
* doAsyncTask(foo, function(err, data) {
4465+
* // handle errors
4466+
* if (err) return callback(err);
4467+
*
4468+
* // do some stuff ...
4469+
*
4470+
* // return processed data
4471+
* return callback(null, data);
4472+
* });
4473+
* }
4474+
*
4475+
* var wrapped = async.timeout(myFunction, 1000);
4476+
*
4477+
* // call `wrapped` as you would `myFunction`
4478+
* wrapped({ bar: 'bar' }, function(err, data) {
4479+
* // if `myFunction` takes < 1000 ms to execute, `err`
4480+
* // and `data` will have their expected values
4481+
*
4482+
* // else `err` will be an Error with the code 'ETIMEDOUT'
4483+
* });
44454484
*/
44464485
function timeout(asyncFn, milliseconds, info) {
44474486
var originalCallback, timer;
@@ -4649,7 +4688,7 @@
46494688
}
46504689

46514690
/**
4652-
* Repeatedly call `fn`, while `test` returns `true`. Calls `callback` when
4691+
* Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
46534692
* stopped, or an error occurs.
46544693
*
46554694
* @name whilst
@@ -4658,13 +4697,13 @@
46584697
* @method
46594698
* @category Control Flow
46604699
* @param {Function} test - synchronous truth test to perform before each
4661-
* execution of `fn`. Invoked with ().
4700+
* execution of `iteratee`. Invoked with ().
46624701
* @param {Function} iteratee - A function which is called each time `test` passes.
46634702
* The function is passed a `callback(err)`, which must be called once it has
46644703
* completed with an optional `err` argument. Invoked with (callback).
46654704
* @param {Function} [callback] - A callback which is called after the test
4666-
* function has failed and repeated execution of `fn` has stopped. `callback`
4667-
* will be passed an error and any arguments passed to the final `fn`'s
4705+
* function has failed and repeated execution of `iteratee` has stopped. `callback`
4706+
* will be passed an error and any arguments passed to the final `iteratee`'s
46684707
* callback. Invoked with (err, [results]);
46694708
* @returns undefined
46704709
* @example

0 commit comments

Comments
 (0)