Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

async-es

Package Overview
Dependencies
Maintainers
4
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-es - npm Package Compare versions

Comparing version 2.6.1 to 3.0.1-0

cargoQueue.js

12

all.js
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import notId from './internal/notId';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -24,2 +24,3 @@ * in the collection in parallel.

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -35,2 +36,5 @@ *

*/
export default doParallel(createTester(notId, notId));
function every(coll, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOf, coll, iteratee, callback)
}
export default awaitify(every, 3);
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import notId from './internal/notId';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -25,3 +25,7 @@ * @param {AsyncFunction} iteratee - An async truth test to apply to each item

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(createTester(notId, notId));
function everyLimit(coll, limit, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(everyLimit, 4);

@@ -1,3 +0,4 @@

import everyLimit from './everyLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOfSeries from './eachOfSeries';
import awaitify from './internal/awaitify';

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -23,3 +24,7 @@ * in the collection in series.

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(everyLimit, 1);
function everySeries(coll, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(everySeries, 3);
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import identity from 'lodash-es/identity';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -16,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -26,2 +26,3 @@ * in the collections in parallel.

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -37,2 +38,5 @@ *

*/
export default doParallel(createTester(Boolean, identity));
function some(coll, iteratee, callback) {
return createTester(Boolean, res => res)(eachOf, coll, iteratee, callback)
}
export default awaitify(some, 3);
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import identity from 'lodash-es/identity';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -26,3 +26,7 @@ * @param {AsyncFunction} iteratee - An async truth test to apply to each item

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(createTester(Boolean, identity));
function someLimit(coll, limit, iteratee, callback) {
return createTester(Boolean, res => res)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(someLimit, 4);

@@ -1,3 +0,4 @@

import someLimit from './someLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOfSeries from './eachOfSeries';
import awaitify from './internal/awaitify';

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -24,3 +25,7 @@ * in the collections in series.

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(someLimit, 1);
function someSeries(coll, iteratee, callback) {
return createTester(Boolean, res => res)(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(someSeries, 3);

@@ -1,3 +0,1 @@

import slice from './internal/slice';
/**

@@ -48,8 +46,4 @@ * Creates a continuation function with some arguments already applied.

*/
export default function(fn/*, ...args*/) {
var args = slice(arguments, 1);
return function(/*callArgs*/) {
var callArgs = slice(arguments);
return fn.apply(null, args.concat(callArgs));
};
};
export default function(fn, ...args) {
return (...callArgs) => fn(...args,...callArgs);
}

@@ -9,3 +9,5 @@ import applyEach from './internal/applyEach';

* arguments as if it were a single function call. If more arguments are
* provided, `callback` is required while `args` is still optional.
* provided, `callback` is required while `args` is still optional. The results
* for each of the applied async functions are passed to the final callback
* as an array.
*

@@ -17,3 +19,3 @@ * @name applyEach

* @category Control Flow
* @param {Array|Iterable|Object} fns - A collection of {@link AsyncFunction}s
* @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s
* to all call with the same arguments

@@ -30,3 +32,6 @@ * @param {...*} [args] - any number of separate arguments to pass to the

*
* async.applyEach([enableSearch, updateSchema], 'bucket', callback);
* async.applyEach([enableSearch, updateSchema], 'bucket', (err, results) => {
* // results[0] is the results for `enableSearch`
* // results[1] is the results for `updateSchema`
* });
*

@@ -33,0 +38,0 @@ * // partial application example:

@@ -13,3 +13,3 @@ import applyEach from './internal/applyEach';

* @category Control Flow
* @param {Array|Iterable|Object} fns - A collection of {@link AsyncFunction}s to all
* @param {Array|Iterable|AsyncIterable|Object} fns - A collection of {@link AsyncFunction}s to all
* call with the same arguments

@@ -16,0 +16,0 @@ * @param {...*} [args] - any number of separate arguments to pass to the

@@ -1,4 +0,4 @@

import isObject from 'lodash-es/isObject';
import initialParams from './internal/initialParams';
import setImmediate from './internal/setImmediate';
import { isAsync } from './internal/wrapAsync'

@@ -62,2 +62,10 @@ /**

export default function asyncify(func) {
if (isAsync(func)) {
return function (...args/*, callback*/) {
const callback = args.pop()
const promise = func.apply(this, args)
return handlePromise(promise, callback)
}
}
return initialParams(function (args, callback) {

@@ -71,8 +79,4 @@ var result;

// if result is Promise object
if (isObject(result) && typeof result.then === 'function') {
result.then(function(value) {
invokeCallback(callback, null, value);
}, function(err) {
invokeCallback(callback, err.message ? err : new Error(err));
});
if (result && typeof result.then === 'function') {
return handlePromise(result, callback)
} else {

@@ -84,12 +88,16 @@ callback(null, result);

function handlePromise(promise, callback) {
return promise.then(value => {
invokeCallback(callback, null, value);
}, err => {
invokeCallback(callback, err && err.message ? err : new Error(err));
});
}
function invokeCallback(callback, error, value) {
try {
callback(error, value);
} catch (e) {
setImmediate(rethrow, e);
} catch (err) {
setImmediate(e => { throw e }, err);
}
}
function rethrow(error) {
throw error;
}

@@ -1,12 +0,5 @@

import arrayEach from 'lodash-es/_arrayEach';
import forOwn from 'lodash-es/_baseForOwn';
import indexOf from 'lodash-es/_baseIndexOf';
import isArray from 'lodash-es/isArray';
import okeys from 'lodash-es/keys';
import noop from 'lodash-es/noop';
import slice from './internal/slice';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback'

@@ -51,3 +44,3 @@ /**

* will only contain partial results. Invoked with (err, results).
* @returns undefined
* @returns {Promise} a promise, if a callback is not passed
* @example

@@ -93,4 +86,4 @@ *

*/
export default function (tasks, concurrency, callback) {
if (typeof concurrency === 'function') {
export default function auto(tasks, concurrency, callback) {
if (typeof concurrency !== 'number') {
// concurrency is optional, shift the args.

@@ -100,5 +93,4 @@ callback = concurrency;

}
callback = once(callback || noop);
var keys = okeys(tasks);
var numTasks = keys.length;
callback = once(callback || promiseCallback());
var numTasks = Object.keys(tasks).length;
if (!numTasks) {

@@ -113,2 +105,3 @@ return callback(null);

var runningTasks = 0;
var canceled = false;
var hasError = false;

@@ -125,4 +118,5 @@

forOwn(tasks, function (task, key) {
if (!isArray(task)) {
Object.keys(tasks).forEach(key => {
var task = tasks[key]
if (!Array.isArray(task)) {
// no dependencies

@@ -143,3 +137,3 @@ enqueueTask(key, [task]);

arrayEach(dependencies, function (dependencyName) {
dependencies.forEach(dependencyName => {
if (!tasks[dependencyName]) {

@@ -151,3 +145,3 @@ throw new Error('async.auto task `' + key +

}
addListener(dependencyName, function () {
addListener(dependencyName, () => {
remainingDependencies--;

@@ -165,8 +159,7 @@ if (remainingDependencies === 0) {

function enqueueTask(key, task) {
readyTasks.push(function () {
runTask(key, task);
});
readyTasks.push(() => runTask(key, task));
}
function processQueue() {
if (canceled) return
if (readyTasks.length === 0 && runningTasks === 0) {

@@ -193,5 +186,3 @@ return callback(null, results);

var taskListeners = listeners[taskName] || [];
arrayEach(taskListeners, function (fn) {
fn();
});
taskListeners.forEach(fn => fn());
processQueue();

@@ -204,11 +195,15 @@ }

var taskCallback = onlyOnce(function(err, result) {
var taskCallback = onlyOnce((err, ...result) => {
runningTasks--;
if (arguments.length > 2) {
result = slice(arguments, 1);
if (err === false) {
canceled = true
return
}
if (result.length < 2) {
[result] = result;
}
if (err) {
var safeResults = {};
forOwn(results, function(val, rkey) {
safeResults[rkey] = val;
Object.keys(results).forEach(rkey => {
safeResults[rkey] = results[rkey];
});

@@ -218,3 +213,3 @@ safeResults[key] = result;

listeners = Object.create(null);
if (canceled) return
callback(err, safeResults);

@@ -245,3 +240,3 @@ } else {

counter++;
arrayEach(getDependents(currentTask), function (dependent) {
getDependents(currentTask).forEach(dependent => {
if (--uncheckedDependencies[dependent] === 0) {

@@ -262,4 +257,5 @@ readyToCheck.push(dependent);

var result = [];
forOwn(tasks, function (task, key) {
if (isArray(task) && indexOf(task, taskName, 0) >= 0) {
Object.keys(tasks).forEach(key => {
const task = tasks[key]
if (Array.isArray(task) && task.indexOf(taskName) >= 0) {
result.push(key);

@@ -270,2 +266,4 @@ }

}
return callback[PROMISE_SYMBOL]
}
import auto from './auto';
import forOwn from 'lodash-es/_baseForOwn';
import arrayMap from 'lodash-es/_arrayMap';
import isArray from 'lodash-es/isArray';
import trim from 'lodash-es/trim';
import wrapAsync from './internal/wrapAsync';
import { isAsync } from './internal/wrapAsync';
var FN_ARGS = /^(?:async\s+)?(function)?\s*[^\(]*\(\s*([^\)]*)\)/m;
var FN_ARGS = /^(?:async\s+)?(?:function)?\s*[^(]*\(\s*([^)]+)\s*\)(?:\s*{)/m;
var ARROW_FN_ARGS = /^(?:async\s+)?\(?\s*([^)^=]+)\s*\)?(?:\s*=>)/m;
var FN_ARG_SPLIT = /,/;

@@ -15,9 +12,13 @@ var FN_ARG = /(=.+)?(\s*)$/;

function parseParams(func) {
func = func.toString().replace(STRIP_COMMENTS, '');
func = func.match(FN_ARGS)[2].replace(' ', '');
func = func ? func.split(FN_ARG_SPLIT) : [];
func = func.map(function (arg){
return trim(arg.replace(FN_ARG, ''));
});
return func;
const src = func.toString().replace(STRIP_COMMENTS, '');
let match = src.match(FN_ARGS)
if (!match) {
match = src.match(ARROW_FN_ARGS);
}
if (!match) throw new Error('could not parse args in autoInject\nSource:\n' + src)
let [, args] = match
return args
.replace(/\s/g, '')
.split(FN_ARG_SPLIT)
.map((arg) => arg.replace(FN_ARG, '').trim());
}

@@ -57,2 +58,3 @@

* task results, similar to `auto`.
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -111,3 +113,4 @@ *

forOwn(tasks, function (taskFn, key) {
Object.keys(tasks).forEach(key => {
var taskFn = tasks[key]
var params;

@@ -119,5 +122,5 @@ var fnIsAsync = isAsync(taskFn);

if (isArray(taskFn)) {
params = taskFn.slice(0, -1);
taskFn = taskFn[taskFn.length - 1];
if (Array.isArray(taskFn)) {
params = [...taskFn];
taskFn = params.pop();

@@ -130,3 +133,3 @@ newTasks[key] = params.concat(params.length > 0 ? newTask : taskFn);

params = parseParams(taskFn);
if (taskFn.length === 0 && !fnIsAsync && params.length === 0) {
if ((taskFn.length === 0 && !fnIsAsync) && params.length === 0) {
throw new Error("autoInject task functions require explicit parameters.");

@@ -142,11 +145,9 @@ }

function newTask(results, taskCb) {
var newArgs = arrayMap(params, function (name) {
return results[name];
});
var newArgs = params.map(name => results[name])
newArgs.push(taskCb);
wrapAsync(taskFn).apply(null, newArgs);
wrapAsync(taskFn)(...newArgs);
}
});
auto(newTasks, callback);
return auto(newTasks, callback);
}

@@ -0,1 +1,37 @@

# v3.0.0
The `async`/`await` release!
There are a lot of new features and subtle breaking changes in this major version, but the biggest feature is that most Async methods return a Promise if you omit the callback, meaning you can `await` them from within an `async` function.
```js
const results = await async.mapLimit(urls, 5, async url => {
const resp = await fetch(url)
return resp.body
})
```
## Breaking Changes
- Most Async methods return a Promise when the final callback is omitted, making them `await`-able! (#1572)
- We are now making heavy use of ES2015 features, this means we have dropped out-of-the-box support for Node 4 and earlier, and many old versions of browsers. (#1541, #1553)
- Calling `callback(false)` will cancel an async method, preventing further iteration and callback calls. This is useful for preventing memory leaks when you break out of an async flow by calling an outer callback. (#1064, #1542)
- `during` and `doDuring` have been removed, and instead `whilst`, `doWhilst`, `until` and `doUntil` now have asynchronous `test` functions. (#850, #1557)
- `limits` of less than 1 now cause an error to be thrown in queues and collection methods. (#1249, #1552)
- `memoize` no longer memoizes errors (#1465, #1466)
## New Features
- Async generators are now supported in all the Collection methods. (#1560)
- Added `cargoQueue`, a queue with both `concurrency` and `payload` size parameters. (#1567)
- Queue objects returned from `queue` now have a `Symbol.iterator` method, meaning they can be iterated over to inspect the current list of items in the queue. (#1459, #1556)
## Bug fixes
- Better handle arbitrary error objects in `asyncify` (#1568, #1569)
## Other
- Removed Lodash as a dependency (#1283, #1528)
- Miscellaneous docs fixes (#1393, #1501, #1540, #1543, #1558, #1563, #1564, #1579, #1581)
- Miscellaneous test fixes (#1538)
-------
# v2.6.1

@@ -2,0 +38,0 @@ - Updated lodash to prevent `npm audit` warnings. (#1532, #1533)

import seq from './seq';
import slice from './internal/slice';

@@ -10,2 +9,5 @@ /**

*
* If the last argument to the composed function is not a function, a promise
* is returned when you call it.
*
* Each function is executed with the `this` binding of the composed function.

@@ -40,4 +42,4 @@ *

*/
export default function(/*...args*/) {
return seq.apply(null, slice(arguments).reverse());
};
export default function compose(...args) {
return seq(...args.reverse());
}

@@ -1,3 +0,3 @@

import doLimit from './internal/doLimit';
import concatLimit from './concatLimit';
import awaitify from './internal/awaitify'

@@ -7,5 +7,4 @@ /**

* the concatenated list. The `iteratee`s are called in parallel, and the
* results are concatenated as they return. There is no guarantee that the
* results array will be returned in the original order of `coll` passed to the
* `iteratee` function.
* results are concatenated as they return. The results array will be returned in
* the original order of `coll` passed to the `iteratee` function.
*

@@ -17,9 +16,10 @@ * @name concat

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,
* which should use an array as its result. Invoked with (item, callback).
* @param {Function} [callback(err)] - A callback which is called after all the
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished, or an error occurs. Results is an array
* containing the concatenated results of the `iteratee` function. Invoked with
* (err, results).
* @returns A Promise, if no callback is passed
* @example

@@ -31,2 +31,5 @@ *

*/
export default doLimit(concatLimit, Infinity);
function concat(coll, iteratee, callback) {
return concatLimit(coll, Infinity, iteratee, callback)
}
export default awaitify(concat, 3);

@@ -1,8 +0,5 @@

import noop from 'lodash-es/noop';
import wrapAsync from './internal/wrapAsync';
import slice from './internal/slice';
import mapLimit from './mapLimit';
import awaitify from './internal/awaitify'
var _concat = Array.prototype.concat;
/**

@@ -17,3 +14,3 @@ * The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -26,16 +23,16 @@ * @param {AsyncFunction} iteratee - A function to apply to each item in `coll`,

* (err, results).
* @returns A Promise, if no callback is passed
*/
export default function(coll, limit, iteratee, callback) {
callback = callback || noop;
function concatLimit(coll, limit, iteratee, callback) {
var _iteratee = wrapAsync(iteratee);
mapLimit(coll, limit, function(val, callback) {
_iteratee(val, function(err /*, ...args*/) {
if (err) return callback(err);
return callback(null, slice(arguments, 1));
return mapLimit(coll, limit, (val, iterCb) => {
_iteratee(val, (err, ...args) => {
if (err) return iterCb(err);
return iterCb(null, args);
});
}, function(err, mapResults) {
}, (err, mapResults) => {
var result = [];
for (var i = 0; i < mapResults.length; i++) {
if (mapResults[i]) {
result = _concat.apply(result, mapResults[i]);
result = result.concat(...mapResults[i]);
}

@@ -47,1 +44,2 @@ }

}
export default awaitify(concatLimit, 4)

@@ -1,3 +0,3 @@

import doLimit from './internal/doLimit';
import concatLimit from './concatLimit';
import awaitify from './internal/awaitify'

@@ -13,11 +13,15 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A function to apply to each item in `coll`.
* The iteratee should complete with an array an array of results.
* Invoked with (item, callback).
* @param {Function} [callback(err)] - A callback which is called after all the
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished, or an error occurs. Results is an array
* containing the concatenated results of the `iteratee` function. Invoked with
* (err, results).
* @returns A Promise, if no callback is passed
*/
export default doLimit(concatLimit, 1);
function concatSeries(coll, iteratee, callback) {
return concatLimit(coll, 1, iteratee, callback)
}
export default awaitify(concatSeries, 3);

@@ -1,3 +0,1 @@

import slice from './internal/slice';
/**

@@ -45,9 +43,7 @@ * Returns a function that when called, calls-back with the values provided.

*/
export default function(/*...values*/) {
var values = slice(arguments);
var args = [null].concat(values);
return function (/*...ignoredArgs, callback*/) {
var callback = arguments[arguments.length - 1];
return callback.apply(this, args);
export default function(...args) {
return function (...ignoredArgs/*, callback*/) {
var callback = ignoredArgs.pop();
return callback(null, ...args);
};
};
}

@@ -1,6 +0,4 @@

import identity from 'lodash-es/identity';
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import findGetResult from './internal/findGetResult';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -23,3 +21,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

@@ -33,2 +31,3 @@ * The iteratee must complete with a boolean value as its result.

* (err, result).
* @returns A Promise, if no callback is passed
* @example

@@ -44,2 +43,5 @@ *

*/
export default doParallel(createTester(identity, findGetResult));
function detect(coll, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOf, coll, iteratee, callback)
}
export default awaitify(detect, 3)

@@ -1,6 +0,4 @@

import identity from 'lodash-es/identity';
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import findGetResult from './internal/findGetResult';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -18,3 +16,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -29,3 +27,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

* (err, result).
* @returns a Promise if no callback is passed
*/
export default doParallelLimit(createTester(identity, findGetResult));
function detectLimit(coll, limit, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(detectLimit, 4)

@@ -1,3 +0,4 @@

import detectLimit from './detectLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester'
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -14,3 +15,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

@@ -24,3 +25,8 @@ * The iteratee must complete with a boolean value as its result.

* (err, result).
* @returns a Promise if no callback is passed
*/
export default doLimit(detectLimit, 1);
function detectSeries(coll, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOfLimit(1), coll, iteratee, callback)
}
export default awaitify(detectSeries, 3)

@@ -1,47 +0,51 @@

import noop from 'lodash-es/noop';
import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'
/**
* The post-check version of [`during`]{@link module:ControlFlow.during}. To reflect the difference in
* the order of operations, the arguments `test` and `fn` are switched.
* The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
* the order of operations, the arguments `test` and `iteratee` are switched.
*
* Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
* @name doDuring
* `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
*
* @name doWhilst
* @static
* @memberOf module:ControlFlow
* @method
* @see [async.during]{@link module:ControlFlow.during}
* @see [async.whilst]{@link module:ControlFlow.whilst}
* @category Control Flow
* @param {AsyncFunction} fn - An async function which is called each time
* `test` passes. Invoked with (callback).
* @param {AsyncFunction} test - asynchronous truth test to perform before each
* execution of `fn`. Invoked with (...args, callback), where `...args` are the
* non-error args from the previous callback of `fn`.
* @param {AsyncFunction} iteratee - A function which is called each time `test`
* passes. Invoked with (callback).
* @param {AsyncFunction} test - asynchronous truth test to perform after each
* execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
* non-error args from the previous callback of `iteratee`.
* @param {Function} [callback] - A callback which is called after the test
* function has failed and repeated execution of `fn` has stopped. `callback`
* will be passed an error if one occurred, otherwise `null`.
* function has failed and repeated execution of `iteratee` has stopped.
* `callback` will be passed an error and any arguments passed to the final
* `iteratee`'s callback. Invoked with (err, [results]);
* @returns {Promise} a promise, if no callback is passed
*/
export default function doDuring(fn, test, callback) {
callback = onlyOnce(callback || noop);
var _fn = wrapAsync(fn);
function doWhilst(iteratee, test, callback) {
callback = onlyOnce(callback);
var _fn = wrapAsync(iteratee);
var _test = wrapAsync(test);
var results
function next(err/*, ...args*/) {
function next(err, ...args) {
if (err) return callback(err);
var args = slice(arguments, 1);
args.push(check);
_test.apply(this, args);
};
if (err === false) return;
results = args
_test(...args, check);
}
function check(err, truth) {
if (err) return callback(err);
if (!truth) return callback(null);
if (err === false) return;
if (!truth) return callback(null, ...results);
_fn(next);
}
check(null, true);
return check(null, true);
}
export default awaitify(doWhilst, 3)
import doWhilst from './doWhilst';
import wrapAsync from './internal/wrapAsync';

@@ -15,5 +16,5 @@ /**

* `test` fails. Invoked with (callback).
* @param {Function} test - synchronous truth test to perform after each
* execution of `iteratee`. Invoked with any non-error callback results of
* `iteratee`.
* @param {AsyncFunction} test - asynchronous truth test to perform after each
* execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
* non-error args from the previous callback of `iteratee`
* @param {Function} [callback] - A callback which is called after the test

@@ -23,7 +24,10 @@ * function has passed and repeated execution of `iteratee` has stopped. `callback`

* callback. Invoked with (err, [results]);
* @returns {Promise} a promise, if no callback is passed
*/
export default function doUntil(iteratee, test, callback) {
doWhilst(iteratee, function() {
return !test.apply(this, arguments);
const _test = wrapAsync(test)
return doWhilst(iteratee, (...args) => {
const cb = args.pop()
_test(...args, (err, truth) => cb (err, !truth))
}, callback);
}

@@ -1,6 +0,4 @@

import noop from 'lodash-es/noop';
import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -21,5 +19,5 @@ /**

* passes. Invoked with (callback).
* @param {Function} test - synchronous truth test to perform after each
* execution of `iteratee`. Invoked with any non-error callback results of
* `iteratee`.
* @param {AsyncFunction} test - asynchronous truth test to perform after each
* execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
* non-error args from the previous callback of `iteratee`.
* @param {Function} [callback] - A callback which is called after the test

@@ -29,13 +27,27 @@ * function has failed and repeated execution of `iteratee` has stopped.

* `iteratee`'s callback. Invoked with (err, [results]);
* @returns {Promise} a promise, if no callback is passed
*/
export default function doWhilst(iteratee, test, callback) {
callback = onlyOnce(callback || noop);
var _iteratee = wrapAsync(iteratee);
var next = function(err/*, ...args*/) {
function doWhilst(iteratee, test, callback) {
callback = onlyOnce(callback);
var _fn = wrapAsync(iteratee);
var _test = wrapAsync(test);
var results
function next(err, ...args) {
if (err) return callback(err);
var args = slice(arguments, 1);
if (test.apply(this, args)) return _iteratee(next);
callback.apply(null, [null].concat(args));
};
_iteratee(next);
if (err === false) return;
results = args
_test(...args, check);
}
function check(err, truth) {
if (err) return callback(err);
if (err === false) return;
if (!truth) return callback(null, ...results);
_fn(next);
}
return check(null, true);
}
export default awaitify(doWhilst, 3)

@@ -1,48 +0,49 @@

import noop from 'lodash-es/noop';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify';
/**
* Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
* is passed a callback in the form of `function (err, truth)`. If error is
* passed to `test` or `fn`, the main callback is immediately called with the
* value of the error.
* Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
* stopped, or an error occurs.
*
* @name during
* @name whilst
* @static
* @memberOf module:ControlFlow
* @method
* @see [async.whilst]{@link module:ControlFlow.whilst}
* @category Control Flow
* @param {AsyncFunction} test - asynchronous truth test to perform before each
* execution of `fn`. Invoked with (callback).
* @param {AsyncFunction} fn - An async function which is called each time
* execution of `iteratee`. Invoked with ().
* @param {AsyncFunction} iteratee - An async function which is called each time
* `test` passes. Invoked with (callback).
* @param {Function} [callback] - A callback which is called after the test
* function has failed and repeated execution of `fn` has stopped. `callback`
* will be passed an error, if one occurred, otherwise `null`.
* function has failed and repeated execution of `iteratee` has stopped. `callback`
* will be passed an error and any arguments passed to the final `iteratee`'s
* callback. Invoked with (err, [results]);
* @returns {Promise} a promise, if no callback is passed
* @example
*
* var count = 0;
*
* async.during(
* function (callback) {
* return callback(null, count < 5);
* },
* function (callback) {
* async.whilst(
* function test(cb) { cb(null, count < 5;) },
* function iter(callback) {
* count++;
* setTimeout(callback, 1000);
* setTimeout(function() {
* callback(null, count);
* }, 1000);
* },
* function (err) {
* // 5 seconds have passed
* function (err, n) {
* // 5 seconds have passed, n = 5
* }
* );
*/
export default function during(test, fn, callback) {
callback = onlyOnce(callback || noop);
var _fn = wrapAsync(fn);
function whilst(test, iteratee, callback) {
callback = onlyOnce(callback);
var _fn = wrapAsync(iteratee);
var _test = wrapAsync(test);
var results
function next(err) {
function next(err, ...rest) {
if (err) return callback(err);
results = rest;
if (err === false) return;
_test(check);

@@ -53,7 +54,9 @@ }

if (err) return callback(err);
if (!truth) return callback(null);
if (err === false) return;
if (!truth) return callback(null, ...results);
_fn(next);
}
_test(check);
return _test(check);
}
export default awaitify(whilst, 3)
import eachOf from './eachOf';
import withoutIndex from './internal/withoutIndex';
import wrapAsync from './internal/wrapAsync'
import awaitify from './internal/awaitify'

@@ -21,3 +22,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to

@@ -29,2 +30,3 @@ * each item in `coll`. Invoked with (item, callback).

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example

@@ -64,4 +66,6 @@ *

*/
export default function eachLimit(coll, iteratee, callback) {
eachOf(coll, withoutIndex(wrapAsync(iteratee)), callback);
function eachLimit(coll, iteratee, callback) {
return eachOf(coll, withoutIndex(wrapAsync(iteratee)), callback);
}
export default awaitify(eachLimit, 3)
import eachOfLimit from './internal/eachOfLimit';
import withoutIndex from './internal/withoutIndex';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -25,5 +26,7 @@ * @param {AsyncFunction} iteratee - An async function to apply to each item in

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default function eachLimit(coll, limit, iteratee, callback) {
eachOfLimit(limit)(coll, withoutIndex(wrapAsync(iteratee)), callback);
function eachLimit(coll, limit, iteratee, callback) {
return eachOfLimit(limit)(coll, withoutIndex(wrapAsync(iteratee)), callback);
}
export default awaitify(eachLimit, 4)

@@ -1,17 +0,16 @@

import isArrayLike from 'lodash-es/isArrayLike';
import isArrayLike from './internal/isArrayLike';
import breakLoop from './internal/breakLoop';
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import noop from 'lodash-es/noop';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'
// eachOf implementation optimized for array-likes
function eachOfArrayLike(coll, iteratee, callback) {
callback = once(callback || noop);
callback = once(callback);
var index = 0,
completed = 0,
length = coll.length;
{length} = coll,
canceled = false;
if (length === 0) {

@@ -22,2 +21,6 @@ callback(null);

function iteratorCallback(err, value) {
if (err === false) {
canceled = true
}
if (canceled === true) return
if (err) {

@@ -36,3 +39,5 @@ callback(err);

// a generic version of eachOf which can handle array, object, and iterator cases.
var eachOfGeneric = doLimit(eachOfLimit, Infinity);
function eachOfGeneric (coll, iteratee, callback) {
return eachOfLimit(coll, Infinity, iteratee, callback);
}

@@ -50,3 +55,3 @@ /**

* @see [async.each]{@link module:Collections.each}
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A function to apply to each

@@ -58,2 +63,3 @@ * item in `coll`.

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example

@@ -80,5 +86,7 @@ *

*/
export default function(coll, iteratee, callback) {
function eachOf(coll, iteratee, callback) {
var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
eachOfImplementation(coll, wrapAsync(iteratee), callback);
return eachOfImplementation(coll, wrapAsync(iteratee), callback);
}
export default awaitify(eachOf, 3)
import _eachOfLimit from './internal/eachOfLimit';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -24,5 +25,8 @@ * @param {AsyncFunction} iteratee - An async function to apply to each

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default function eachOfLimit(coll, limit, iteratee, callback) {
_eachOfLimit(limit)(coll, wrapAsync(iteratee), callback);
function eachOfLimit(coll, limit, iteratee, callback) {
return _eachOfLimit(limit)(coll, wrapAsync(iteratee), callback);
}
export default awaitify(eachOfLimit, 4)
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import awaitify from './internal/awaitify'

@@ -14,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -21,3 +21,7 @@ * `coll`.

* functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default doLimit(eachOfLimit, 1);
function eachOfSeries(coll, iteratee, callback) {
return eachOfLimit(coll, 1, iteratee, callback)
}
export default awaitify(eachOfSeries, 3);
import eachLimit from './eachLimit';
import doLimit from './internal/doLimit';
import awaitify from './internal/awaitify'

@@ -14,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each

@@ -23,3 +23,7 @@ * item in `coll`.

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default doLimit(eachLimit, 1);
function eachSeries(coll, iteratee, callback) {
return eachLimit(coll, 1, iteratee, callback)
}
export default awaitify(eachSeries, 3);
import setImmediate from './internal/setImmediate';
import initialParams from './internal/initialParams';
import { isAsync } from './internal/wrapAsync';

@@ -42,12 +41,10 @@

if (isAsync(fn)) return fn;
return initialParams(function (args, callback) {
return function (...args/*, callback*/) {
var callback = args.pop()
var sync = true;
args.push(function () {
var innerArgs = arguments;
args.push((...innerArgs) => {
if (sync) {
setImmediate(function () {
callback.apply(null, innerArgs);
});
setImmediate(() => callback(...innerArgs));
} else {
callback.apply(null, innerArgs);
callback(...innerArgs);
}

@@ -57,3 +54,3 @@ });

sync = false;
});
};
}
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import notId from './internal/notId';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -24,2 +24,3 @@ * in the collection in parallel.

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -35,2 +36,5 @@ *

*/
export default doParallel(createTester(notId, notId));
function every(coll, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOf, coll, iteratee, callback)
}
export default awaitify(every, 3);
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import notId from './internal/notId';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -25,3 +25,7 @@ * @param {AsyncFunction} iteratee - An async truth test to apply to each item

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(createTester(notId, notId));
function everyLimit(coll, limit, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(everyLimit, 4);

@@ -1,3 +0,4 @@

import everyLimit from './everyLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOfSeries from './eachOfSeries';
import awaitify from './internal/awaitify';

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -23,3 +24,7 @@ * in the collection in series.

* depending on the values of the async tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(everyLimit, 1);
function everySeries(coll, iteratee, callback) {
return createTester(bool => !bool, res => !res)(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(everySeries, 3);

@@ -1,3 +0,4 @@

import filter from './internal/filter';
import doParallel from './internal/doParallel';
import _filter from './internal/filter';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - A truth test to apply to each item in `coll`.

@@ -22,2 +23,3 @@ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -33,2 +35,5 @@ *

*/
export default doParallel(filter);
function filter (coll, iteratee, callback) {
return _filter(eachOf, coll, iteratee, callback)
}
export default awaitify(filter, 3);

@@ -1,3 +0,4 @@

import filter from './internal/filter';
import doParallelLimit from './internal/doParallelLimit';
import _filter from './internal/filter';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -23,3 +24,7 @@ * @param {Function} iteratee - A truth test to apply to each item in `coll`.

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(filter);
function filterLimit (coll, limit, iteratee, callback) {
return _filter(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(filterLimit, 4);

@@ -1,3 +0,4 @@

import filterLimit from './filterLimit';
import doLimit from './internal/doLimit';
import _filter from './internal/filter';
import eachOfSeries from './eachOfSeries'
import awaitify from './internal/awaitify'

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - A truth test to apply to each item in `coll`.

@@ -21,3 +22,7 @@ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called

* `iteratee` functions have finished. Invoked with (err, results)
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(filterLimit, 1);
function filterSeries (coll, iteratee, callback) {
return _filter(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(filterSeries, 3);

@@ -1,6 +0,4 @@

import identity from 'lodash-es/identity';
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import findGetResult from './internal/findGetResult';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -23,3 +21,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

@@ -33,2 +31,3 @@ * The iteratee must complete with a boolean value as its result.

* (err, result).
* @returns A Promise, if no callback is passed
* @example

@@ -44,2 +43,5 @@ *

*/
export default doParallel(createTester(identity, findGetResult));
function detect(coll, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOf, coll, iteratee, callback)
}
export default awaitify(detect, 3)

@@ -1,6 +0,4 @@

import identity from 'lodash-es/identity';
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import findGetResult from './internal/findGetResult';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -18,3 +16,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -29,3 +27,7 @@ * @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

* (err, result).
* @returns a Promise if no callback is passed
*/
export default doParallelLimit(createTester(identity, findGetResult));
function detectLimit(coll, limit, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(detectLimit, 4)

@@ -1,3 +0,4 @@

import detectLimit from './detectLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester'
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -14,3 +15,3 @@ /**

* @category Collections
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A truth test to apply to each item in `coll`.

@@ -24,3 +25,8 @@ * The iteratee must complete with a boolean value as its result.

* (err, result).
* @returns a Promise if no callback is passed
*/
export default doLimit(detectLimit, 1);
function detectSeries(coll, iteratee, callback) {
return createTester(bool => bool, (res, item) => item)(eachOfLimit(1), coll, iteratee, callback)
}
export default awaitify(detectSeries, 3)
import eachOfSeries from './eachOfSeries';
import noop from 'lodash-es/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -24,3 +24,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {*} memo - The initial state of the reduction.

@@ -36,2 +36,3 @@ * @param {AsyncFunction} iteratee - A function applied to each item in the

* (err, result).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -48,13 +49,13 @@ *

*/
export default function reduce(coll, memo, iteratee, callback) {
callback = once(callback || noop);
function reduce(coll, memo, iteratee, callback) {
callback = once(callback);
var _iteratee = wrapAsync(iteratee);
eachOfSeries(coll, function(x, i, callback) {
_iteratee(memo, x, function(err, v) {
return eachOfSeries(coll, (x, i, iterCb) => {
_iteratee(memo, x, (err, v) => {
memo = v;
callback(err);
iterCb(err);
});
}, function(err) {
callback(err, memo);
});
}, err => callback(err, memo));
}
export default awaitify(reduce, 4)
import reduce from './reduce';
import slice from './internal/slice';

@@ -25,6 +24,7 @@ /**

* (err, result).
* @returns {Promise} a promise, if no callback is passed
*/
export default function reduceRight (array, memo, iteratee, callback) {
var reversed = slice(array).reverse();
reduce(reversed, memo, iteratee, callback);
var reversed = [...array].reverse();
return reduce(reversed, memo, iteratee, callback);
}
import eachOf from './eachOf';
import withoutIndex from './internal/withoutIndex';
import wrapAsync from './internal/wrapAsync'
import awaitify from './internal/awaitify'

@@ -21,3 +22,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to

@@ -29,2 +30,3 @@ * each item in `coll`. Invoked with (item, callback).

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example

@@ -64,4 +66,6 @@ *

*/
export default function eachLimit(coll, iteratee, callback) {
eachOf(coll, withoutIndex(wrapAsync(iteratee)), callback);
function eachLimit(coll, iteratee, callback) {
return eachOf(coll, withoutIndex(wrapAsync(iteratee)), callback);
}
export default awaitify(eachLimit, 3)
import eachOfLimit from './internal/eachOfLimit';
import withoutIndex from './internal/withoutIndex';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -25,5 +26,7 @@ * @param {AsyncFunction} iteratee - An async function to apply to each item in

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default function eachLimit(coll, limit, iteratee, callback) {
eachOfLimit(limit)(coll, withoutIndex(wrapAsync(iteratee)), callback);
function eachLimit(coll, limit, iteratee, callback) {
return eachOfLimit(limit)(coll, withoutIndex(wrapAsync(iteratee)), callback);
}
export default awaitify(eachLimit, 4)

@@ -1,17 +0,16 @@

import isArrayLike from 'lodash-es/isArrayLike';
import isArrayLike from './internal/isArrayLike';
import breakLoop from './internal/breakLoop';
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import noop from 'lodash-es/noop';
import once from './internal/once';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'
// eachOf implementation optimized for array-likes
function eachOfArrayLike(coll, iteratee, callback) {
callback = once(callback || noop);
callback = once(callback);
var index = 0,
completed = 0,
length = coll.length;
{length} = coll,
canceled = false;
if (length === 0) {

@@ -22,2 +21,6 @@ callback(null);

function iteratorCallback(err, value) {
if (err === false) {
canceled = true
}
if (canceled === true) return
if (err) {

@@ -36,3 +39,5 @@ callback(err);

// a generic version of eachOf which can handle array, object, and iterator cases.
var eachOfGeneric = doLimit(eachOfLimit, Infinity);
function eachOfGeneric (coll, iteratee, callback) {
return eachOfLimit(coll, Infinity, iteratee, callback);
}

@@ -50,3 +55,3 @@ /**

* @see [async.each]{@link module:Collections.each}
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - A function to apply to each

@@ -58,2 +63,3 @@ * item in `coll`.

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
* @example

@@ -80,5 +86,7 @@ *

*/
export default function(coll, iteratee, callback) {
function eachOf(coll, iteratee, callback) {
var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
eachOfImplementation(coll, wrapAsync(iteratee), callback);
return eachOfImplementation(coll, wrapAsync(iteratee), callback);
}
export default awaitify(eachOf, 3)
import _eachOfLimit from './internal/eachOfLimit';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -24,5 +25,8 @@ * @param {AsyncFunction} iteratee - An async function to apply to each

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default function eachOfLimit(coll, limit, iteratee, callback) {
_eachOfLimit(limit)(coll, wrapAsync(iteratee), callback);
function eachOfLimit(coll, limit, iteratee, callback) {
return _eachOfLimit(limit)(coll, wrapAsync(iteratee), callback);
}
export default awaitify(eachOfLimit, 4)
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import awaitify from './internal/awaitify'

@@ -14,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -21,3 +21,7 @@ * `coll`.

* functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default doLimit(eachOfLimit, 1);
function eachOfSeries(coll, iteratee, callback) {
return eachOfLimit(coll, 1, iteratee, callback)
}
export default awaitify(eachOfSeries, 3);
import eachLimit from './eachLimit';
import doLimit from './internal/doLimit';
import awaitify from './internal/awaitify'

@@ -14,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each

@@ -23,3 +23,7 @@ * item in `coll`.

* `iteratee` functions have finished, or an error occurs. Invoked with (err).
* @returns {Promise} a promise, if a callback is omitted
*/
export default doLimit(eachLimit, 1);
function eachSeries(coll, iteratee, callback) {
return eachLimit(coll, 1, iteratee, callback)
}
export default awaitify(eachSeries, 3);

@@ -1,6 +0,5 @@

import noop from 'lodash-es/noop';
import onlyOnce from './internal/onlyOnce';
import ensureAsync from './ensureAsync';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -23,2 +22,4 @@ /**

* this function will be called, and execution stops. Invoked with (err).
* @returns {Promise} a promise that rejects if an error occurs and an errback
* is not passed
* @example

@@ -37,4 +38,4 @@ *

*/
export default function forever(fn, errback) {
var done = onlyOnce(errback || noop);
function forever(fn, errback) {
var done = onlyOnce(errback);
var task = wrapAsync(ensureAsync(fn));

@@ -44,5 +45,7 @@

if (err) return done(err);
if (err === false) return;
task(next);
}
next();
return next();
}
export default awaitify(forever, 2)

@@ -1,2 +0,1 @@

import doLimit from './internal/doLimit';
import groupByLimit from './groupByLimit';

@@ -20,3 +19,3 @@

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -29,2 +28,3 @@ * `coll`.

* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -42,2 +42,4 @@ *

*/
export default doLimit(groupByLimit, Infinity);
export default function groupBy (coll, iteratee, callback) {
return groupByLimit(coll, Infinity, iteratee, callback)
}

@@ -1,4 +0,5 @@

import noop from 'lodash-es/noop';
import mapLimit from './mapLimit';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'
/**

@@ -13,3 +14,3 @@ * The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -23,20 +24,20 @@ * @param {AsyncFunction} iteratee - An async function to apply to each item in

* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
*/
export default function(coll, limit, iteratee, callback) {
callback = callback || noop;
function groupByLimit(coll, limit, iteratee, callback) {
var _iteratee = wrapAsync(iteratee);
mapLimit(coll, limit, function(val, callback) {
_iteratee(val, function(err, key) {
if (err) return callback(err);
return callback(null, {key: key, val: val});
return mapLimit(coll, limit, (val, iterCb) => {
_iteratee(val, (err, key) => {
if (err) return iterCb(err);
return iterCb(null, {key, val});
});
}, function(err, mapResults) {
}, (err, mapResults) => {
var result = {};
// from MDN, handle object having an `hasOwnProperty` prop
var hasOwnProperty = Object.prototype.hasOwnProperty;
var {hasOwnProperty} = Object.prototype;
for (var i = 0; i < mapResults.length; i++) {
if (mapResults[i]) {
var key = mapResults[i].key;
var val = mapResults[i].val;
var {key} = mapResults[i];
var {val} = mapResults[i];

@@ -53,2 +54,4 @@ if (hasOwnProperty.call(result, key)) {

});
};
}
export default awaitify(groupByLimit, 4);

@@ -1,2 +0,1 @@

import doLimit from './internal/doLimit';
import groupByLimit from './groupByLimit';

@@ -13,4 +12,3 @@

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -23,3 +21,6 @@ * `coll`.

* properties are arrays of values which returned the corresponding key.
* @returns {Promise} a promise, if no callback is passed
*/
export default doLimit(groupByLimit, 1);
export default function groupBySeries (coll, iteratee, callback) {
return groupByLimit(coll, 1, iteratee, callback)
}

@@ -73,2 +73,3 @@ /**

import cargo from './cargo'
import cargoQueue from './cargoQueue'
import compose from './compose'

@@ -83,6 +84,4 @@ import concat from './concat'

import dir from './dir'
import doDuring from './doDuring'
import doUntil from './doUntil'
import doWhilst from './doWhilst'
import during from './during'
import each from './each'

@@ -147,79 +146,78 @@ import eachLimit from './eachLimit'

export default {
apply: apply,
applyEach: applyEach,
applyEachSeries: applyEachSeries,
asyncify: asyncify,
auto: auto,
autoInject: autoInject,
cargo: cargo,
compose: compose,
concat: concat,
concatLimit: concatLimit,
concatSeries: concatSeries,
constant: constant,
detect: detect,
detectLimit: detectLimit,
detectSeries: detectSeries,
dir: dir,
doDuring: doDuring,
doUntil: doUntil,
doWhilst: doWhilst,
during: during,
each: each,
eachLimit: eachLimit,
eachOf: eachOf,
eachOfLimit: eachOfLimit,
eachOfSeries: eachOfSeries,
eachSeries: eachSeries,
ensureAsync: ensureAsync,
every: every,
everyLimit: everyLimit,
everySeries: everySeries,
filter: filter,
filterLimit: filterLimit,
filterSeries: filterSeries,
forever: forever,
groupBy: groupBy,
groupByLimit: groupByLimit,
groupBySeries: groupBySeries,
log: log,
map: map,
mapLimit: mapLimit,
mapSeries: mapSeries,
mapValues: mapValues,
mapValuesLimit: mapValuesLimit,
mapValuesSeries: mapValuesSeries,
memoize: memoize,
nextTick: nextTick,
parallel: parallel,
parallelLimit: parallelLimit,
priorityQueue: priorityQueue,
queue: queue,
race: race,
reduce: reduce,
reduceRight: reduceRight,
reflect: reflect,
reflectAll: reflectAll,
reject: reject,
rejectLimit: rejectLimit,
rejectSeries: rejectSeries,
retry: retry,
retryable: retryable,
seq: seq,
series: series,
setImmediate: setImmediate,
some: some,
someLimit: someLimit,
someSeries: someSeries,
sortBy: sortBy,
timeout: timeout,
times: times,
timesLimit: timesLimit,
timesSeries: timesSeries,
transform: transform,
tryEach: tryEach,
unmemoize: unmemoize,
until: until,
waterfall: waterfall,
whilst: whilst,
apply,
applyEach,
applyEachSeries,
asyncify,
auto,
autoInject,
cargo,
cargoQueue,
compose,
concat,
concatLimit,
concatSeries,
constant,
detect,
detectLimit,
detectSeries,
dir,
doUntil,
doWhilst,
each,
eachLimit,
eachOf,
eachOfLimit,
eachOfSeries,
eachSeries,
ensureAsync,
every,
everyLimit,
everySeries,
filter,
filterLimit,
filterSeries,
forever,
groupBy,
groupByLimit,
groupBySeries,
log,
map,
mapLimit,
mapSeries,
mapValues,
mapValuesLimit,
mapValuesSeries,
memoize,
nextTick,
parallel,
parallelLimit,
priorityQueue,
queue,
race,
reduce,
reduceRight,
reflect,
reflectAll,
reject,
rejectLimit,
rejectSeries,
retry,
retryable,
seq,
series,
setImmediate,
some,
someLimit,
someSeries,
sortBy,
timeout,
times,
timesLimit,
timesSeries,
transform,
tryEach,
unmemoize,
until,
waterfall,
whilst,

@@ -248,3 +246,5 @@ // aliases

selectSeries: filterSeries,
wrapSync: asyncify
wrapSync: asyncify,
during: whilst,
doDuring: doWhilst
};

@@ -260,2 +260,3 @@

cargo as cargo,
cargoQueue as cargoQueue,
compose as compose,

@@ -270,6 +271,4 @@ concat as concat,

dir as dir,
doDuring as doDuring,
doUntil as doUntil,
doWhilst as doWhilst,
during as during,
each as each,

@@ -355,4 +354,6 @@ eachLimit as eachLimit,

filterSeries as selectSeries,
asyncify as wrapSync
asyncify as wrapSync,
whilst as during,
doWhilst as doDuring
};
import eachOfSeries from './eachOfSeries';
import noop from 'lodash-es/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -24,3 +24,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {*} memo - The initial state of the reduction.

@@ -36,2 +36,3 @@ * @param {AsyncFunction} iteratee - A function applied to each item in the

* (err, result).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -48,13 +49,13 @@ *

*/
export default function reduce(coll, memo, iteratee, callback) {
callback = once(callback || noop);
function reduce(coll, memo, iteratee, callback) {
callback = once(callback);
var _iteratee = wrapAsync(iteratee);
eachOfSeries(coll, function(x, i, callback) {
_iteratee(memo, x, function(err, v) {
return eachOfSeries(coll, (x, i, iterCb) => {
_iteratee(memo, x, (err, v) => {
memo = v;
callback(err);
iterCb(err);
});
}, function(err) {
callback(err, memo);
});
}, err => callback(err, memo));
}
export default awaitify(reduce, 4)

@@ -1,2 +0,1 @@

import slice from './slice';
import initialParams from './initialParams';

@@ -6,17 +5,14 @@ import wrapAsync from './wrapAsync';

export default function applyEach(eachfn) {
return function(fns/*, ...args*/) {
var args = slice(arguments, 1);
return function(fns, ...callArgs) {
var go = initialParams(function(args, callback) {
var that = this;
return eachfn(fns, function (fn, cb) {
return eachfn(fns, (fn, cb) => {
wrapAsync(fn).apply(that, args.concat(cb));
}, callback);
});
if (args.length) {
return go.apply(this, args);
if (callArgs.length) {
return go.apply(this, callArgs);
}
else {
return go;
}
return go;
};
}
// A temporary value used to identify if the loop should be broken.
// See #1064, #1293
export default {};
const breakLoop = {};
export default breakLoop;

@@ -1,24 +0,15 @@

import arrayEach from 'lodash-es/_arrayEach';
import slice from './slice';
import wrapAsync from './wrapAsync';
export default function consoleFunc(name) {
return function (fn/*, ...args*/) {
var args = slice(arguments, 1);
args.push(function (err/*, ...args*/) {
var args = slice(arguments, 1);
if (typeof console === 'object') {
if (err) {
if (console.error) {
console.error(err);
}
} else if (console[name]) {
arrayEach(args, function (x) {
console[name](x);
});
return (fn, ...args) => wrapAsync(fn)(...args, (err, ...resultArgs) => {
if (typeof console === 'object') {
if (err) {
if (console.error) {
console.error(err);
}
} else if (console[name]) {
resultArgs.forEach(x => console[name](x));
}
})
wrapAsync(fn).apply(null, args);
};
}
})
}

@@ -1,29 +0,25 @@

import noop from 'lodash-es/noop';
import breakLoop from './breakLoop';
import wrapAsync from './wrapAsync'
export default function _createTester(check, getResult) {
return function(eachfn, arr, iteratee, cb) {
cb = cb || noop;
return (eachfn, arr, _iteratee, cb) => {
var testPassed = false;
var testResult;
eachfn(arr, function(value, _, callback) {
iteratee(value, function(err, result) {
if (err) {
callback(err);
} else if (check(result) && !testResult) {
const iteratee = wrapAsync(_iteratee)
eachfn(arr, (value, _, callback) => {
iteratee(value, (err, result) => {
if (err) return callback(err)
if (check(result) && !testResult) {
testPassed = true;
testResult = getResult(true, value);
callback(null, breakLoop);
} else {
callback();
return callback(null, breakLoop);
}
callback();
});
}, function(err) {
if (err) {
cb(err);
} else {
cb(null, testPassed ? testResult : getResult(false));
}
}, err => {
if (err) return cb(err);
cb(null, testPassed ? testResult : getResult(false));
});
};
}

@@ -5,84 +5,89 @@ // Simple doubly linked list (https://en.wikipedia.org/wiki/Doubly_linked_list) implementation

// for queue support.
export default function DLL() {
this.head = this.tail = null;
this.length = 0;
}
export default class DLL {
constructor() {
this.head = this.tail = null;
this.length = 0;
}
function setInitial(dll, node) {
dll.length = 1;
dll.head = dll.tail = node;
}
removeLink(node) {
if (node.prev) node.prev.next = node.next;
else this.head = node.next
if (node.next) node.next.prev = node.prev;
else this.tail = node.prev;
DLL.prototype.removeLink = function(node) {
if (node.prev) node.prev.next = node.next;
else this.head = node.next
if (node.next) node.next.prev = node.prev;
else this.tail = node.prev;
node.prev = node.next = null;
this.length -= 1;
return node;
}
node.prev = node.next = null;
this.length -= 1;
return node;
}
empty () {
while(this.head) this.shift();
return this;
}
DLL.prototype.empty = function () {
while(this.head) this.shift();
return this;
};
insertAfter(node, newNode) {
newNode.prev = node;
newNode.next = node.next;
if (node.next) node.next.prev = newNode;
else this.tail = newNode;
node.next = newNode;
this.length += 1;
}
DLL.prototype.insertAfter = function(node, newNode) {
newNode.prev = node;
newNode.next = node.next;
if (node.next) node.next.prev = newNode;
else this.tail = newNode;
node.next = newNode;
this.length += 1;
}
insertBefore(node, newNode) {
newNode.prev = node.prev;
newNode.next = node;
if (node.prev) node.prev.next = newNode;
else this.head = newNode;
node.prev = newNode;
this.length += 1;
}
DLL.prototype.insertBefore = function(node, newNode) {
newNode.prev = node.prev;
newNode.next = node;
if (node.prev) node.prev.next = newNode;
else this.head = newNode;
node.prev = newNode;
this.length += 1;
}
unshift(node) {
if (this.head) this.insertBefore(this.head, node);
else setInitial(this, node);
}
DLL.prototype.unshift = function(node) {
if (this.head) this.insertBefore(this.head, node);
else setInitial(this, node);
};
push(node) {
if (this.tail) this.insertAfter(this.tail, node);
else setInitial(this, node);
}
DLL.prototype.push = function(node) {
if (this.tail) this.insertAfter(this.tail, node);
else setInitial(this, node);
};
shift() {
return this.head && this.removeLink(this.head);
}
DLL.prototype.shift = function() {
return this.head && this.removeLink(this.head);
};
pop() {
return this.tail && this.removeLink(this.tail);
}
DLL.prototype.pop = function() {
return this.tail && this.removeLink(this.tail);
};
toArray() {
return [...this]
}
DLL.prototype.toArray = function () {
var arr = Array(this.length);
var curr = this.head;
for(var idx = 0; idx < this.length; idx++) {
arr[idx] = curr.data;
curr = curr.next;
*[Symbol.iterator] () {
var cur = this.head
while (cur) {
yield cur.data
cur = cur.next
}
}
return arr;
}
DLL.prototype.remove = function (testFn) {
var curr = this.head;
while(!!curr) {
var next = curr.next;
if (testFn(curr)) {
this.removeLink(curr);
remove (testFn) {
var curr = this.head;
while(curr) {
var {next} = curr;
if (testFn(curr)) {
this.removeLink(curr);
}
curr = next;
}
curr = next;
return this;
}
return this;
}
function setInitial(dll, node) {
dll.length = 1;
dll.head = dll.tail = node;
}

@@ -1,2 +0,1 @@

import noop from 'lodash-es/noop';
import once from './once';

@@ -6,13 +5,25 @@

import onlyOnce from './onlyOnce';
import {isAsyncGenerator, isAsyncIterable} from './wrapAsync'
import asyncEachOfLimit from './asyncEachOfLimit'
import breakLoop from './breakLoop';
export default function _eachOfLimit(limit) {
return function (obj, iteratee, callback) {
callback = once(callback || noop);
if (limit <= 0 || !obj) {
export default (limit) => {
return (obj, iteratee, callback) => {
callback = once(callback);
if (limit <= 0) {
throw new RangeError('concurrency limit cannot be less than 1')
}
if (!obj) {
return callback(null);
}
if (isAsyncGenerator(obj)) {
return asyncEachOfLimit(obj, limit, iteratee, callback)
}
if (isAsyncIterable(obj)) {
return asyncEachOfLimit(obj[Symbol.asyncIterator](), limit, iteratee, callback)
}
var nextElem = iterator(obj);
var done = false;
var canceled = false;
var running = 0;

@@ -22,2 +33,3 @@ var looping = false;

function iterateeCallback(err, value) {
if (canceled) return
running -= 1;

@@ -28,2 +40,6 @@ if (err) {

}
else if (err === false) {
done = true;
canceled = true;
}
else if (value === breakLoop || (done && running <= 0)) {

@@ -30,0 +46,0 @@ done = true;

@@ -1,5 +0,2 @@

import arrayMap from 'lodash-es/_arrayMap';
import isArrayLike from 'lodash-es/isArrayLike';
import property from 'lodash-es/_baseProperty';
import noop from 'lodash-es/noop';
import isArrayLike from './isArrayLike';

@@ -10,8 +7,8 @@ import wrapAsync from './wrapAsync';

var truthValues = new Array(arr.length);
eachfn(arr, function (x, index, callback) {
iteratee(x, function (err, v) {
eachfn(arr, (x, index, iterCb) => {
iteratee(x, (err, v) => {
truthValues[index] = !!v;
callback(err);
iterCb(err);
});
}, function (err) {
}, err => {
if (err) return callback(err);

@@ -28,21 +25,15 @@ var results = [];

var results = [];
eachfn(coll, function (x, index, callback) {
iteratee(x, function (err, v) {
if (err) {
callback(err);
} else {
if (v) {
results.push({index: index, value: x});
}
callback();
eachfn(coll, (x, index, iterCb) => {
iteratee(x, (err, v) => {
if (err) return iterCb(err);
if (v) {
results.push({index, value: x});
}
iterCb();
});
}, function (err) {
if (err) {
callback(err);
} else {
callback(null, arrayMap(results.sort(function (a, b) {
return a.index - b.index;
}), property('value')));
}
}, err => {
if (err) return callback(err);
callback(null, results
.sort((a, b) => a.index - b.index)
.map(v => v.value));
});

@@ -53,3 +44,3 @@ }

var filter = isArrayLike(coll) ? filterArray : filterGeneric;
filter(eachfn, coll, wrapAsync(iteratee), callback || noop);
return filter(eachfn, coll, wrapAsync(iteratee), callback);
}

@@ -1,5 +0,3 @@

var iteratorSymbol = typeof Symbol === 'function' && Symbol.iterator;
export default function (coll) {
return iteratorSymbol && coll[iteratorSymbol] && coll[iteratorSymbol]();
return coll[Symbol.iterator] && coll[Symbol.iterator]();
}

@@ -1,9 +0,6 @@

import slice from './slice';
export default function (fn) {
return function (/*...args, callback*/) {
var args = slice(arguments);
return function (...args/*, callback*/) {
var callback = args.pop();
fn.call(this, args, callback);
return fn.call(this, args, callback);
};
}

@@ -1,4 +0,3 @@

import isArrayLike from 'lodash-es/isArrayLike';
import isArrayLike from './isArrayLike';
import getIterator from './getIterator';
import keys from 'lodash-es/keys';

@@ -25,3 +24,3 @@ function createArrayIterator(coll) {

function createObjectIterator(obj) {
var okeys = keys(obj);
var okeys = obj ? Object.keys(obj) : [];
var i = -1;

@@ -31,7 +30,7 @@ var len = okeys.length;

var key = okeys[++i];
return i < len ? {value: obj[key], key: key} : null;
return i < len ? {value: obj[key], key} : null;
};
}
export default function iterator(coll) {
export default function createIterator(coll) {
if (isArrayLike(coll)) {

@@ -38,0 +37,0 @@ return createArrayIterator(coll);

@@ -1,6 +0,4 @@

import noop from 'lodash-es/noop';
import wrapAsync from './wrapAsync';
export default function _asyncMap(eachfn, arr, iteratee, callback) {
callback = callback || noop;
arr = arr || [];

@@ -11,11 +9,11 @@ var results = [];

eachfn(arr, function (value, _, callback) {
return eachfn(arr, (value, _, iterCb) => {
var index = counter++;
_iteratee(value, function (err, v) {
_iteratee(value, (err, v) => {
results[index] = v;
callback(err);
iterCb(err);
});
}, function (err) {
}, err => {
callback(err, results);
});
}
export default function once(fn) {
return function () {
function wrapper (...args) {
if (fn === null) return;
var callFn = fn;
fn = null;
callFn.apply(this, arguments);
};
callFn.apply(this, args);
}
Object.assign(wrapper, fn)
return wrapper
}
export default function onlyOnce(fn) {
return function() {
return function (...args) {
if (fn === null) throw new Error("Callback was already called.");
var callFn = fn;
fn = null;
callFn.apply(this, arguments);
callFn.apply(this, args);
};
}

@@ -1,21 +0,17 @@

import noop from 'lodash-es/noop';
import isArrayLike from 'lodash-es/isArrayLike';
import slice from './slice';
import isArrayLike from './isArrayLike';
import wrapAsync from './wrapAsync';
import awaitify from './awaitify'
export default function _parallel(eachfn, tasks, callback) {
callback = callback || noop;
export default awaitify((eachfn, tasks, callback) => {
var results = isArrayLike(tasks) ? [] : {};
eachfn(tasks, function (task, key, callback) {
wrapAsync(task)(function (err, result) {
if (arguments.length > 2) {
result = slice(arguments, 1);
eachfn(tasks, (task, key, taskCb) => {
wrapAsync(task)((err, ...result) => {
if (result.length < 2) {
[result] = result;
}
results[key] = result;
callback(err);
taskCb(err);
});
}, function (err) {
callback(err, results);
});
}
}, err => callback(err, results));
}, 3)

@@ -1,5 +0,1 @@

import indexOf from 'lodash-es/_baseIndexOf';
import isArray from 'lodash-es/isArray';
import noop from 'lodash-es/noop';
import onlyOnce from './onlyOnce';

@@ -10,2 +6,4 @@ import setImmediate from './setImmediate';

const noop = () => {}
export default function queue(worker, concurrency, payload) {

@@ -16,3 +14,3 @@ if (concurrency == null) {

else if(concurrency === 0) {
throw new Error('Concurrency must not be zero');
throw new RangeError('Concurrency must not be zero');
}

@@ -30,3 +28,3 @@

q.started = true;
if (!isArray(data)) {
if (!Array.isArray(data)) {
data = [data];

@@ -36,5 +34,3 @@ }

// call drain immediately if there are no tasks
return setImmediate(function() {
q.drain();
});
return setImmediate(() => q.drain());
}

@@ -57,3 +53,3 @@

processingScheduled = true;
setImmediate(function() {
setImmediate(() => {
processingScheduled = false;

@@ -66,3 +62,3 @@ q.process();

function _next(tasks) {
return function(err){
return function (err, ...args) {
numRunning -= 1;

@@ -73,3 +69,3 @@

var index = indexOf(workersList, task, 0);
var index = workersList.indexOf(task);
if (index === 0) {

@@ -81,3 +77,3 @@ workersList.shift();

task.callback.apply(task, arguments);
task.callback(err, ...args);

@@ -103,4 +99,7 @@ if (err != null) {

_tasks: new DLL(),
concurrency: concurrency,
payload: payload,
*[Symbol.iterator] () {
yield* q._tasks[Symbol.iterator]()
},
concurrency,
payload,
saturated: noop,

@@ -114,16 +113,16 @@ unsaturated:noop,

paused: false,
push: function (data, callback) {
push (data, callback) {
_insert(data, false, callback);
},
kill: function () {
kill () {
q.drain = noop;
q._tasks.empty();
},
unshift: function (data, callback) {
unshift (data, callback) {
_insert(data, true, callback);
},
remove: function (testFn) {
remove (testFn) {
q._tasks.remove(testFn);
},
process: function () {
process () {
// Avoid trying to start too many processing operations. This can occur

@@ -161,18 +160,18 @@ // when callbacks resolve synchronously (#1267).

},
length: function () {
length () {
return q._tasks.length;
},
running: function () {
running () {
return numRunning;
},
workersList: function () {
workersList () {
return workersList;
},
idle: function() {
idle() {
return q._tasks.length + numRunning === 0;
},
pause: function () {
pause () {
q.paused = true;
},
resume: function () {
resume () {
if (q.paused === false) { return; }

@@ -179,0 +178,0 @@ q.paused = false;

import filter from './filter';
import wrapAsync from './wrapAsync'
export default function reject(eachfn, arr, iteratee, callback) {
filter(eachfn, arr, function(value, cb) {
iteratee(value, function(err, v) {
export default function reject(eachfn, arr, _iteratee, callback) {
const iteratee = wrapAsync(_iteratee)
return filter(eachfn, arr, (value, cb) => {
iteratee(value, (err, v) => {
cb(err, !v);

@@ -7,0 +9,0 @@ });

'use strict';
import slice from './slice';
export var hasSetImmediate = typeof setImmediate === 'function' && setImmediate;

@@ -13,8 +11,3 @@ export var hasNextTick = typeof process === 'object' && typeof process.nextTick === 'function';

export function wrap(defer) {
return function (fn/*, ...args*/) {
var args = slice(arguments, 1);
defer(function () {
fn.apply(null, args);
});
};
return (fn, ...args) => defer(() => fn(...args));
}

@@ -21,0 +14,0 @@

export default function _withoutIndex(iteratee) {
return function (value, index, callback) {
return iteratee(value, callback);
};
return (value, index, callback) => iteratee(value, callback);
}
import asyncify from '../asyncify';
var supportsSymbol = typeof Symbol === 'function';
function isAsync(fn) {
return supportsSymbol && fn[Symbol.toStringTag] === 'AsyncFunction';
return fn[Symbol.toStringTag] === 'AsyncFunction';
}
function isAsyncGenerator(fn) {
return fn[Symbol.toStringTag] === 'AsyncGenerator';
}
function isAsyncIterable(obj) {
return typeof obj[Symbol.asyncIterator] === 'function';
}
function wrapAsync(asyncFn) {
if (typeof asyncFn !== 'function') throw new Error('expected a function')
return isAsync(asyncFn) ? asyncify(asyncFn) : asyncFn;

@@ -15,2 +22,2 @@ }

export { isAsync };
export { isAsync, isAsyncGenerator, isAsyncIterable };

@@ -1,3 +0,4 @@

import doParallel from './internal/doParallel';
import map from './internal/map';
import _map from './internal/map';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -26,3 +27,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -35,2 +36,3 @@ * `coll`.

* transformed items from the `coll`. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -42,2 +44,5 @@ *

*/
export default doParallel(map);
function map (coll, iteratee, callback) {
return _map(eachOf, coll, iteratee, callback)
}
export default awaitify(map, 3);

@@ -1,3 +0,4 @@

import doParallelLimit from './internal/doParallelLimit';
import map from './internal/map';
import _map from './internal/map';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -13,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -23,3 +24,7 @@ * @param {AsyncFunction} iteratee - An async function to apply to each item in

* transformed items from the `coll`. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
*/
export default doParallelLimit(map);
function mapLimit (coll, limit, iteratee, callback) {
return _map(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(mapLimit, 4);

@@ -1,3 +0,4 @@

import mapLimit from './mapLimit';
import doLimit from './internal/doLimit';
import _map from './internal/map';
import eachOfSeries from './eachOfSeries'
import awaitify from './internal/awaitify'

@@ -13,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -22,3 +23,7 @@ * `coll`.

* transformed items from the `coll`. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
*/
export default doLimit(mapLimit, 1);
function mapSeries (coll, iteratee, callback) {
return _map(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(mapSeries, 3);
import mapValuesLimit from './mapValuesLimit';
import doLimit from './internal/doLimit';
/**

@@ -32,2 +30,3 @@ * A relative of [`map`]{@link module:Collections.map}, designed for use with objects.

* Invoked with (err, result).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -50,3 +49,4 @@ *

*/
export default doLimit(mapValuesLimit, Infinity);
export default function mapValues(obj, iteratee, callback) {
return mapValuesLimit(obj, Infinity, iteratee, callback)
}

@@ -1,4 +0,3 @@

import eachOfLimit from './eachOfLimit';
import noop from 'lodash-es/noop';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'
import once from './internal/once';

@@ -27,9 +26,10 @@ import wrapAsync from './internal/wrapAsync';

* Invoked with (err, result).
* @returns {Promise} a promise, if no callback is passed
*/
export default function mapValuesLimit(obj, limit, iteratee, callback) {
callback = once(callback || noop);
function mapValuesLimit(obj, limit, iteratee, callback) {
callback = once(callback);
var newObj = {};
var _iteratee = wrapAsync(iteratee)
eachOfLimit(obj, limit, function(val, key, next) {
_iteratee(val, key, function (err, result) {
return eachOfLimit(limit)(obj, (val, key, next) => {
_iteratee(val, key, (err, result) => {
if (err) return next(err);

@@ -39,5 +39,5 @@ newObj[key] = result;

});
}, function (err) {
callback(err, newObj);
});
}, err => callback(err, newObj));
}
export default awaitify(mapValuesLimit, 4)
import mapValuesLimit from './mapValuesLimit';
import doLimit from './internal/doLimit';

@@ -22,3 +21,6 @@ /**

* Invoked with (err, result).
* @returns {Promise} a promise, if no callback is passed
*/
export default doLimit(mapValuesLimit, 1);
export default function mapValuesSeries(obj, iteratee, callback) {
return mapValuesLimit(obj, 1, iteratee, callback)
}

@@ -1,4 +0,1 @@

import identity from 'lodash-es/identity';
import slice from './internal/slice';
import setImmediate from './internal/setImmediate';

@@ -8,6 +5,2 @@ import initialParams from './internal/initialParams';

function has(obj, key) {
return key in obj;
}
/**

@@ -18,2 +11,5 @@ * Caches the results of an async function. When creating a hash to store

*
* **Note: if the async function errs, the result will not be cached and
* subsequent calls will call the wrapped function.**
*
* If no hash function is specified, the first argument is used as a hash key,

@@ -51,26 +47,25 @@ * which may work reasonably if it is a string or a data type that converts to a

*/
export default function memoize(fn, hasher) {
export default function memoize(fn, hasher = v => v) {
var memo = Object.create(null);
var queues = Object.create(null);
hasher = hasher || identity;
var _fn = wrapAsync(fn);
var memoized = initialParams(function memoized(args, callback) {
var key = hasher.apply(null, args);
if (has(memo, key)) {
setImmediate(function() {
callback.apply(null, memo[key]);
});
} else if (has(queues, key)) {
var memoized = initialParams((args, callback) => {
var key = hasher(...args);
if (key in memo) {
setImmediate(() => callback(null, ...memo[key]));
} else if (key in queues) {
queues[key].push(callback);
} else {
queues[key] = [callback];
_fn.apply(null, args.concat(function(/*args*/) {
var args = slice(arguments);
memo[key] = args;
_fn(...args, (err, ...resultArgs) => {
// #1465 don't memoize if an error occurred
if (!err) {
memo[key] = resultArgs;
}
var q = queues[key];
delete queues[key];
for (var i = 0, l = q.length; i < l; i++) {
q[i].apply(null, args);
q[i](err, ...resultArgs);
}
}));
});
}

@@ -77,0 +72,0 @@ });

{
"name": "async-es",
"description": "Higher-order functions and common patterns for asynchronous code",
"version": "2.6.1",
"version": "3.0.1-0",
"main": "index.js",

@@ -21,13 +21,14 @@ "author": "Caolan McMahon",

],
"dependencies": {
"lodash-es": "^4.17.10"
},
"dependencies": {},
"devDependencies": {
"babel-cli": "^6.24.0",
"babel-core": "^6.26.3",
"babel-eslint": "^8.2.6",
"babel-minify": "^0.4.3",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-istanbul": "^2.0.1",
"babel-plugin-syntax-async-generators": "^6.13.0",
"babel-plugin-transform-es2015-modules-commonjs": "^6.26.2",
"babel-preset-es2015": "^6.3.13",
"babel-preset-es2017": "^6.22.0",
"babel-register": "^6.26.0",
"babelify": "^8.0.0",

@@ -41,8 +42,9 @@ "benchmark": "^2.1.1",

"es6-promise": "^2.3.0",
"eslint": "^2.13.1",
"eslint": "^4.19.1",
"eslint-plugin-prefer-arrow": "^1.1.2",
"fs-extra": "^0.26.7",
"gh-pages-deploy": "^0.5.0",
"jsdoc": "^3.4.0",
"karma": "^2.0.2",
"karma-browserify": "^5.2.0",
"karma": "^2.0.5",
"karma-browserify": "^5.3.0",
"karma-firefox-launcher": "^1.1.0",

@@ -55,3 +57,3 @@ "karma-mocha": "^1.2.0",

"rimraf": "^2.5.0",
"rollup": "^0.36.3",
"rollup": "^0.63.4",
"rollup-plugin-node-resolve": "^2.0.0",

@@ -61,3 +63,2 @@ "rollup-plugin-npm": "^2.0.0",

"semver": "^5.5.0",
"uglify-js": "~2.7.3",
"yargs": "^11.0.0"

@@ -69,5 +70,5 @@ },

"jsdoc": "jsdoc -c ./support/jsdoc/jsdoc.json && node support/jsdoc/jsdoc-fix-html.js",
"lint": "eslint lib/ mocha_test/ perf/memory.js perf/suites.js perf/benchmark.js support/build/ support/*.js karma.conf.js",
"lint": "eslint --fix lib/ test/ perf/memory.js perf/suites.js perf/benchmark.js support/build/ support/*.js karma.conf.js",
"mocha-browser-test": "karma start",
"mocha-node-test": "mocha mocha_test/ --compilers js:babel-core/register",
"mocha-node-test": "mocha",
"mocha-test": "npm run mocha-node-test && npm run mocha-browser-test",

@@ -82,3 +83,3 @@ "test": "npm run lint && npm run mocha-node-test"

"exclude": [
"mocha_test"
"test"
]

@@ -85,0 +86,0 @@ },

import eachOf from './eachOf';
import parallel from './internal/parallel';
import _parallel from './internal/parallel';

@@ -30,3 +30,3 @@ /**

* @category Control Flow
* @param {Array|Iterable|Object} tasks - A collection of
* @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of
* [async functions]{@link AsyncFunction} to run.

@@ -38,2 +38,3 @@ * Each async function can complete with any number of optional `result` values.

* Invoked with (err, results).
* @returns {Promise} a promise, if a callback is not passed
*

@@ -75,4 +76,4 @@ * @example

*/
export default function parallelLimit(tasks, callback) {
parallel(eachOf, tasks, callback);
export default function parallel(tasks, callback) {
return _parallel(eachOf, tasks, callback);
}

@@ -14,3 +14,3 @@ import eachOfLimit from './internal/eachOfLimit';

* @category Control Flow
* @param {Array|Iterable|Object} tasks - A collection of
* @param {Array|Iterable|AsyncIterable|Object} tasks - A collection of
* [async functions]{@link AsyncFunction} to run.

@@ -23,5 +23,6 @@ * Each async function can complete with any number of optional `result` values.

* Invoked with (err, results).
* @returns {Promise} a promise, if a callback is not passed
*/
export default function parallelLimit(tasks, limit, callback) {
parallel(eachOfLimit(limit), tasks, callback);
return parallel(eachOfLimit(limit), tasks, callback);
}

@@ -1,6 +0,2 @@

import isArray from 'lodash-es/isArray';
import noop from 'lodash-es/noop';
import setImmediate from './setImmediate';
import queue from './queue';

@@ -36,4 +32,3 @@

// Override push to accept second parameter representing priority
q.push = function(data, priority, callback) {
if (callback == null) callback = noop;
q.push = function(data, priority = 0, callback = () => {}) {
if (typeof callback !== 'function') {

@@ -43,3 +38,3 @@ throw new Error('task callback must be a function');

q.started = true;
if (!isArray(data)) {
if (!Array.isArray(data)) {
data = [data];

@@ -49,8 +44,5 @@ }

// call drain immediately if there are no tasks
return setImmediate(function() {
q.drain();
});
return setImmediate(() => q.drain());
}
priority = priority || 0;
var nextNode = q._tasks.head;

@@ -64,4 +56,4 @@ while (nextNode && priority >= nextNode.priority) {

data: data[i],
priority: priority,
callback: callback
priority,
callback
};

@@ -68,0 +60,0 @@

@@ -6,3 +6,3 @@ import queue from './internal/queue';

* A queue of tasks for the worker function to complete.
* @typedef {Object} QueueObject
* @typedef {Iterable} QueueObject
* @memberOf module:ControlFlow

@@ -57,2 +57,14 @@ * @property {Function} length - a function returning the number of items

* should be pushed to the queue after calling this function. Invoke with `queue.kill()`.
*
* @example
* const q = aync.queue(worker, 2)
* q.push(item1)
* q.push(item2)
* q.push(item3)
* // queues are iterable, spread into an array to inspect
* const items = [...q] // [item1, item2, item3]
* // or use for of
* for (let item of q) {
* console.log(item)
* }
*/

@@ -77,3 +89,3 @@

* defaults to `1`. If the concurrency is `0`, an error is thrown.
* @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can
* @returns {module:ControlFlow.QueueObject} A queue object to manage the tasks. Callbacks can be
* attached as certain properties to listen for specific events during the

@@ -94,2 +106,7 @@ * lifecycle of the queue.

*
* // assign an error callback
* q.error = function(err, task) {
* console.error('task experienced an error');
* };
*
* // add some items to the queue

@@ -115,5 +132,5 @@ * q.push({name: 'foo'}, function(err) {

var _worker = wrapAsync(worker);
return queue(function (items, cb) {
return queue((items, cb) => {
_worker(items[0], cb);
}, concurrency, 1);
}

@@ -1,5 +0,4 @@

import isArray from 'lodash-es/isArray';
import noop from 'lodash-es/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify';

@@ -42,5 +41,5 @@ /**

*/
export default function race(tasks, callback) {
callback = once(callback || noop);
if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
function race(tasks, callback) {
callback = once(callback);
if (!Array.isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions'));
if (!tasks.length) return callback();

@@ -51,1 +50,3 @@ for (var i = 0, l = tasks.length; i < l; i++) {

}
export default awaitify(race, 2)
import eachOfSeries from './eachOfSeries';
import noop from 'lodash-es/noop';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -24,3 +24,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {*} memo - The initial state of the reduction.

@@ -36,2 +36,3 @@ * @param {AsyncFunction} iteratee - A function applied to each item in the

* (err, result).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -48,13 +49,13 @@ *

*/
export default function reduce(coll, memo, iteratee, callback) {
callback = once(callback || noop);
function reduce(coll, memo, iteratee, callback) {
callback = once(callback);
var _iteratee = wrapAsync(iteratee);
eachOfSeries(coll, function(x, i, callback) {
_iteratee(memo, x, function(err, v) {
return eachOfSeries(coll, (x, i, iterCb) => {
_iteratee(memo, x, (err, v) => {
memo = v;
callback(err);
iterCb(err);
});
}, function(err) {
callback(err, memo);
});
}, err => callback(err, memo));
}
export default awaitify(reduce, 4)
import reduce from './reduce';
import slice from './internal/slice';

@@ -25,6 +24,7 @@ /**

* (err, result).
* @returns {Promise} a promise, if no callback is passed
*/
export default function reduceRight (array, memo, iteratee, callback) {
var reversed = slice(array).reverse();
reduce(reversed, memo, iteratee, callback);
var reversed = [...array].reverse();
return reduce(reversed, memo, iteratee, callback);
}
import initialParams from './internal/initialParams';
import slice from './internal/slice';
import wrapAsync from './internal/wrapAsync';

@@ -47,14 +46,11 @@

return initialParams(function reflectOn(args, reflectCallback) {
args.push(function callback(error, cbArg) {
args.push((error, ...cbArgs) => {
if (error) {
reflectCallback(null, { error: error });
} else {
var value;
if (arguments.length <= 2) {
value = cbArg
} else {
value = slice(arguments, 1);
}
reflectCallback(null, { value: value });
return reflectCallback(null, { error });
}
var value = cbArgs;
if (cbArgs.length <= 1) {
[value] = cbArgs
}
reflectCallback(null, { value });
});

@@ -61,0 +57,0 @@

import reflect from './reflect';
import isArray from 'lodash-es/isArray';
import _arrayMap from 'lodash-es/_arrayMap';
import forOwn from 'lodash-es/_baseForOwn';

@@ -75,8 +72,8 @@ /**

var results;
if (isArray(tasks)) {
results = _arrayMap(tasks, reflect);
if (Array.isArray(tasks)) {
results = tasks.map(reflect);
} else {
results = {};
forOwn(tasks, function(task, key) {
results[key] = reflect.call(this, task);
Object.keys(tasks).forEach(key => {
results[key] = reflect.call(this, tasks[key]);
});

@@ -83,0 +80,0 @@ }

@@ -1,3 +0,4 @@

import reject from './internal/reject';
import doParallel from './internal/doParallel';
import _reject from './internal/reject';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -13,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - An async truth test to apply to each item in

@@ -21,2 +22,3 @@ * `coll`.

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -33,2 +35,5 @@ *

*/
export default doParallel(reject);
function reject (coll, iteratee, callback) {
return _reject(eachOf, coll, iteratee, callback)
}
export default awaitify(reject, 3);

@@ -1,4 +0,4 @@

import reject from './internal/reject';
import doParallelLimit from './internal/doParallelLimit';
import _reject from './internal/reject';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'
/**

@@ -14,3 +14,3 @@ * The same as [`reject`]{@link module:Collections.reject} but runs a maximum of `limit` async operations at a

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -23,3 +23,7 @@ * @param {Function} iteratee - An async truth test to apply to each item in

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
*/
export default doParallelLimit(reject);
function rejectLimit (coll, limit, iteratee, callback) {
return _reject(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(rejectLimit, 4);

@@ -1,3 +0,4 @@

import rejectLimit from './rejectLimit';
import doLimit from './internal/doLimit';
import _reject from './internal/reject';
import eachOfSeries from './eachOfSeries'
import awaitify from './internal/awaitify'

@@ -13,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - An async truth test to apply to each item in

@@ -21,3 +22,7 @@ * `coll`.

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback is passed
*/
export default doLimit(rejectLimit, 1);
function rejectSeries (coll, iteratee, callback) {
return _reject(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(rejectSeries, 3);

@@ -1,5 +0,10 @@

import noop from 'lodash-es/noop';
import constant from 'lodash-es/constant';
import wrapAsync from './internal/wrapAsync';
import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback';
function constant(value) {
return function () {
return value;
}
}
/**

@@ -37,2 +42,3 @@ * Attempts to get a successful response from `task` no more than `times` times

* with (err, results).
* @returns {Promise} a promise if no callback provided
*

@@ -90,6 +96,6 @@ * @example

*/
const DEFAULT_TIMES = 5;
const DEFAULT_INTERVAL = 0;
export default function retry(opts, task, callback) {
var DEFAULT_TIMES = 5;
var DEFAULT_INTERVAL = 0;
var options = {

@@ -100,24 +106,8 @@ times: DEFAULT_TIMES,

function parseTimes(acc, t) {
if (typeof t === 'object') {
acc.times = +t.times || DEFAULT_TIMES;
acc.intervalFunc = typeof t.interval === 'function' ?
t.interval :
constant(+t.interval || DEFAULT_INTERVAL);
acc.errorFilter = t.errorFilter;
} else if (typeof t === 'number' || typeof t === 'string') {
acc.times = +t || DEFAULT_TIMES;
} else {
throw new Error("Invalid arguments for async.retry");
}
}
if (arguments.length < 3 && typeof opts === 'function') {
callback = task || noop;
callback = task || promiseCallback();
task = opts;
} else {
parseTimes(options, opts);
callback = callback || noop;
callback = callback || promiseCallback();
}

@@ -133,3 +123,4 @@

function retryAttempt() {
_task(function(err) {
_task((err, ...args) => {
if (err === false) return
if (err && attempt++ < options.times &&

@@ -140,3 +131,3 @@ (typeof options.errorFilter != 'function' ||

} else {
callback.apply(null, arguments);
callback(err, ...args);
}

@@ -147,2 +138,19 @@ });

retryAttempt();
return callback[PROMISE_SYMBOL]
}
function parseTimes(acc, t) {
if (typeof t === 'object') {
acc.times = +t.times || DEFAULT_TIMES;
acc.intervalFunc = typeof t.interval === 'function' ?
t.interval :
constant(+t.interval || DEFAULT_INTERVAL);
acc.errorFilter = t.errorFilter;
} else if (typeof t === 'number' || typeof t === 'string') {
acc.times = +t || DEFAULT_TIMES;
} else {
throw new Error("Invalid arguments for async.retry");
}
}
import retry from './retry';
import initialParams from './internal/initialParams';
import wrapAsync from './internal/wrapAsync';
import {default as wrapAsync, isAsync} from './internal/wrapAsync';
import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback';

@@ -17,3 +18,4 @@ /**

* @param {Object|number} [opts = {times: 5, interval: 0}| 5] - optional
* options, exactly the same as from `retry`
* options, exactly the same as from `retry`, except for a `opts.arity` that
* is the arity of the `task` function, defaulting to `task.length`
* @param {AsyncFunction} task - the asynchronous function to wrap.

@@ -34,3 +36,3 @@ * This function will be passed any arguments passed to the returned wrapper.

*/
export default function (opts, task) {
export default function retryable (opts, task) {
if (!task) {

@@ -40,6 +42,14 @@ task = opts;

}
let arity = (opts && opts.arity) || task.length
if (isAsync(task)) {
arity += 1
}
var _task = wrapAsync(task);
return initialParams(function (args, callback) {
return initialParams((args, callback) => {
if (args.length < arity - 1 || callback == null) {
args.push(callback)
callback = promiseCallback()
}
function taskFn(cb) {
_task.apply(null, args.concat(cb));
_task(...args, cb);
}

@@ -50,3 +60,4 @@

return callback[PROMISE_SYMBOL]
});
}

@@ -1,3 +0,4 @@

import filter from './internal/filter';
import doParallel from './internal/doParallel';
import _filter from './internal/filter';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - A truth test to apply to each item in `coll`.

@@ -22,2 +23,3 @@ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -33,2 +35,5 @@ *

*/
export default doParallel(filter);
function filter (coll, iteratee, callback) {
return _filter(eachOf, coll, iteratee, callback)
}
export default awaitify(filter, 3);

@@ -1,3 +0,4 @@

import filter from './internal/filter';
import doParallelLimit from './internal/doParallelLimit';
import _filter from './internal/filter';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -23,3 +24,7 @@ * @param {Function} iteratee - A truth test to apply to each item in `coll`.

* `iteratee` functions have finished. Invoked with (err, results).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(filter);
function filterLimit (coll, limit, iteratee, callback) {
return _filter(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(filterLimit, 4);

@@ -1,3 +0,4 @@

import filterLimit from './filterLimit';
import doLimit from './internal/doLimit';
import _filter from './internal/filter';
import eachOfSeries from './eachOfSeries'
import awaitify from './internal/awaitify'

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {Function} iteratee - A truth test to apply to each item in `coll`.

@@ -21,3 +22,7 @@ * The `iteratee` is passed a `callback(err, truthValue)`, which must be called

* `iteratee` functions have finished. Invoked with (err, results)
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(filterLimit, 1);
function filterSeries (coll, iteratee, callback) {
return _filter(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(filterSeries, 3);

@@ -1,6 +0,4 @@

import noop from 'lodash-es/noop';
import slice from './internal/slice';
import reduce from './reduce';
import wrapAsync from './internal/wrapAsync';
import arrayMap from 'lodash-es/_arrayMap';
import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback';

@@ -45,6 +43,5 @@ /**

*/
export default function seq(/*...functions*/) {
var _functions = arrayMap(arguments, wrapAsync);
return function(/*...args*/) {
var args = slice(arguments);
export default function seq(...functions) {
var _functions = functions.map(wrapAsync);
return function (...args) {
var that = this;

@@ -56,15 +53,14 @@

} else {
cb = noop;
cb = promiseCallback();
}
reduce(_functions, args, function(newargs, fn, cb) {
fn.apply(that, newargs.concat(function(err/*, ...nextargs*/) {
var nextargs = slice(arguments, 1);
cb(err, nextargs);
reduce(_functions, args, (newargs, fn, iterCb) => {
fn.apply(that, newargs.concat((err, ...nextargs) => {
iterCb(err, nextargs);
}));
},
function(err, results) {
cb.apply(that, [err].concat(results));
});
(err, results) => cb(err, ...results));
return cb[PROMISE_SYMBOL]
};
}

@@ -1,2 +0,2 @@

import parallel from './internal/parallel';
import _parallel from './internal/parallel';
import eachOfSeries from './eachOfSeries';

@@ -30,3 +30,3 @@

* @category Control Flow
* @param {Array|Iterable|Object} tasks - A collection containing
* @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing
* [async functions]{@link AsyncFunction} to run in series.

@@ -38,2 +38,3 @@ * Each function can complete with any number of optional `result` values.

* with (err, result).
* @return {Promise} a promise, if no callback is passed
* @example

@@ -71,3 +72,3 @@ * async.series([

export default function series(tasks, callback) {
parallel(eachOfSeries, tasks, callback);
return _parallel(eachOfSeries, tasks, callback);
}
import createTester from './internal/createTester';
import doParallel from './internal/doParallel';
import identity from 'lodash-es/identity';
import eachOf from './eachOf'
import awaitify from './internal/awaitify'

@@ -16,3 +16,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -26,2 +26,3 @@ * in the collections in parallel.

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -37,2 +38,5 @@ *

*/
export default doParallel(createTester(Boolean, identity));
function some(coll, iteratee, callback) {
return createTester(Boolean, res => res)(eachOf, coll, iteratee, callback)
}
export default awaitify(some, 3);
import createTester from './internal/createTester';
import doParallelLimit from './internal/doParallelLimit';
import identity from 'lodash-es/identity';
import eachOfLimit from './internal/eachOfLimit'
import awaitify from './internal/awaitify'

@@ -15,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {number} limit - The maximum number of async operations at a time.

@@ -26,3 +26,7 @@ * @param {AsyncFunction} iteratee - An async truth test to apply to each item

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doParallelLimit(createTester(Boolean, identity));
function someLimit(coll, limit, iteratee, callback) {
return createTester(Boolean, res => res)(eachOfLimit(limit), coll, iteratee, callback)
}
export default awaitify(someLimit, 4);

@@ -1,3 +0,4 @@

import someLimit from './someLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOfSeries from './eachOfSeries';
import awaitify from './internal/awaitify';

@@ -14,3 +15,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async truth test to apply to each item

@@ -24,3 +25,7 @@ * in the collections in series.

* tests. Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
*/
export default doLimit(someLimit, 1);
function someSeries(coll, iteratee, callback) {
return createTester(Boolean, res => res)(eachOfSeries, coll, iteratee, callback)
}
export default awaitify(someSeries, 3);

@@ -1,6 +0,4 @@

import arrayMap from 'lodash-es/_arrayMap';
import property from 'lodash-es/_baseProperty';
import map from './map';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -16,3 +14,3 @@ /**

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {AsyncFunction} iteratee - An async function to apply to each item in

@@ -27,2 +25,3 @@ * `coll`.

* calls. Invoked with (err, results).
* @returns {Promise} a promise, if no callback passed
* @example

@@ -56,12 +55,12 @@ *

*/
export default function sortBy (coll, iteratee, callback) {
function sortBy (coll, iteratee, callback) {
var _iteratee = wrapAsync(iteratee);
map(coll, function (x, callback) {
_iteratee(x, function (err, criteria) {
if (err) return callback(err);
callback(null, {value: x, criteria: criteria});
return map(coll, (x, iterCb) => {
_iteratee(x, (err, criteria) => {
if (err) return iterCb(err);
iterCb(null, {value: x, criteria});
});
}, function (err, results) {
}, (err, results) => {
if (err) return callback(err);
callback(null, arrayMap(results.sort(comparator), property('value')));
callback(null, results.sort(comparator).map(v => v.value));
});

@@ -74,1 +73,2 @@

}
export default awaitify(sortBy, 3)

@@ -48,3 +48,3 @@ import initialParams from './internal/initialParams';

return initialParams(function (args, callback) {
return initialParams((args, callback) => {
var timedOut = false;

@@ -64,5 +64,5 @@ var timer;

args.push(function () {
args.push((...cbArgs) => {
if (!timedOut) {
callback.apply(null, arguments);
callback(...cbArgs);
clearTimeout(timer);

@@ -74,4 +74,4 @@ }

timer = setTimeout(timeoutCallback, milliseconds);
fn.apply(null, args);
fn(...args);
});
}
import timesLimit from './timesLimit';
import doLimit from './internal/doLimit';

@@ -18,2 +17,3 @@ /**

* @param {Function} callback - see {@link module:Collections.map}.
* @returns {Promise} a promise, if no callback is provided
* @example

@@ -37,2 +37,4 @@ *

*/
export default doLimit(timesLimit, Infinity);
export default function times (n, iteratee, callback) {
return timesLimit(n, Infinity, iteratee, callback)
}
import mapLimit from './mapLimit';
import range from 'lodash-es/_baseRange';
import range from './internal/range';
import wrapAsync from './internal/wrapAsync';

@@ -20,6 +20,7 @@

* @param {Function} callback - see [async.map]{@link module:Collections.map}.
* @returns {Promise} a promise, if no callback is provided
*/
export default function timeLimit(count, limit, iteratee, callback) {
export default function timesLimit(count, limit, iteratee, callback) {
var _iteratee = wrapAsync(iteratee);
mapLimit(range(0, count, 1), limit, _iteratee, callback);
return mapLimit(range(count), limit, _iteratee, callback);
}
import timesLimit from './timesLimit';
import doLimit from './internal/doLimit';

@@ -17,3 +16,6 @@ /**

* @param {Function} callback - see {@link module:Collections.map}.
* @returns {Promise} a promise, if no callback is provided
*/
export default doLimit(timesLimit, 1);
export default function timesSeries (n, iteratee, callback) {
return timesLimit(n, 1, iteratee, callback)
}

@@ -1,11 +0,9 @@

import isArray from 'lodash-es/isArray';
import noop from 'lodash-es/noop';
import eachOf from './eachOf';
import once from './internal/once';
import wrapAsync from './internal/wrapAsync';
import { promiseCallback, PROMISE_SYMBOL } from './internal/promiseCallback';
/**
* A relative of `reduce`. Takes an Object or Array, and iterates over each
* element in series, each step potentially mutating an `accumulator` value.
* element in parallel, each step potentially mutating an `accumulator` value.
* The type of the accumulator defaults to the type of collection passed in.

@@ -18,3 +16,3 @@ *

* @category Collection
* @param {Array|Iterable|Object} coll - A collection to iterate over.
* @param {Array|Iterable|AsyncIterable|Object} coll - A collection to iterate over.
* @param {*} [accumulator] - The initial state of the transform. If omitted,

@@ -28,2 +26,3 @@ * it will default to an empty Object or Array, depending on the type of `coll`

* Invoked with (err, result).
* @returns {Promise} a promise, if no callback provided
* @example

@@ -34,3 +33,3 @@ *

* process.nextTick(function() {
* acc.push(item * 2)
* acc[index] = item * 2
* callback(null)

@@ -54,15 +53,14 @@ * });

export default function transform (coll, accumulator, iteratee, callback) {
if (arguments.length <= 3) {
if (arguments.length <= 3 && typeof accumulator === 'function') {
callback = iteratee;
iteratee = accumulator;
accumulator = isArray(coll) ? [] : {};
accumulator = Array.isArray(coll) ? [] : {};
}
callback = once(callback || noop);
callback = once(callback || promiseCallback());
var _iteratee = wrapAsync(iteratee);
eachOf(coll, function(v, k, cb) {
eachOf(coll, (v, k, cb) => {
_iteratee(accumulator, v, k, cb);
}, function(err) {
callback(err, accumulator);
});
}, err => callback(err, accumulator));
return callback[PROMISE_SYMBOL]
}

@@ -1,5 +0,4 @@

import noop from 'lodash-es/noop';
import eachSeries from './eachSeries';
import wrapAsync from './internal/wrapAsync';
import slice from './internal/slice';
import awaitify from './internal/awaitify'

@@ -17,3 +16,3 @@ /**

* @category Control Flow
* @param {Array|Iterable|Object} tasks - A collection containing functions to
* @param {Array|Iterable|AsyncIterable|Object} tasks - A collection containing functions to
* run, each function is passed a `callback(err, result)` it must call on

@@ -26,2 +25,3 @@ * completion with an error `err` (which can be `null`) and an optional `result`

* (err, results).
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -45,19 +45,18 @@ * async.tryEach([

*/
export default function tryEach(tasks, callback) {
function tryEach(tasks, callback) {
var error = null;
var result;
callback = callback || noop;
eachSeries(tasks, function(task, callback) {
wrapAsync(task)(function (err, res/*, ...args*/) {
if (arguments.length > 2) {
result = slice(arguments, 1);
return eachSeries(tasks, (task, taskCb) => {
wrapAsync(task)((err, ...args) => {
if (args.length < 2) {
[result] = args;
} else {
result = res;
result = args;
}
error = err;
callback(!err);
taskCb(err ? null : {});
});
}, function () {
callback(error, result);
});
}, () => callback(error, result));
}
export default awaitify(tryEach)

@@ -15,5 +15,5 @@ /**

export default function unmemoize(fn) {
return function () {
return (fn.unmemoized || fn).apply(null, arguments);
return (...args) => {
return (fn.unmemoized || fn)(...args);
};
}
import whilst from './whilst';
import wrapAsync from './internal/wrapAsync';

@@ -16,4 +17,4 @@ /**

* @category Control Flow
* @param {Function} test - synchronous truth test to perform before each
* execution of `iteratee`. Invoked with ().
* @param {AsyncFunction} test - asynchronous truth test to perform before each
* execution of `iteratee`. Invoked with (callback).
* @param {AsyncFunction} iteratee - An async function which is called each time

@@ -25,7 +26,21 @@ * `test` fails. Invoked with (callback).

* callback. Invoked with (err, [results]);
* @returns {Promise} a promise, if a callback is not passed
*
* @example
* const results = []
* async.until(function iter(next) {
* fetchPage(url, (err, body) => {
* if (err) return next(err)
* results = results.concat(body.objects)
* next(err, body)
* })
* }, function test(page, cb) {
* cb(null, page.next == null)
* }, function done (err) {
* // all pages have been fetched
* })
*/
export default function until(test, iteratee, callback) {
whilst(function() {
return !test.apply(this, arguments);
}, iteratee, callback);
const _test = wrapAsync(test)
return whilst((cb) => _test((err, truth) => cb (err, !truth)), iteratee, callback);
}

@@ -1,8 +0,6 @@

import isArray from 'lodash-es/isArray';
import noop from 'lodash-es/noop';
import once from './internal/once';
import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify'

@@ -66,5 +64,5 @@ /**

*/
export default function(tasks, callback) {
callback = once(callback || noop);
if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
function waterfall (tasks, callback) {
callback = once(callback);
if (!Array.isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions'));
if (!tasks.length) return callback();

@@ -75,11 +73,11 @@ var taskIndex = 0;

var task = wrapAsync(tasks[taskIndex++]);
args.push(onlyOnce(next));
task.apply(null, args);
task(...args, onlyOnce(next));
}
function next(err/*, ...args*/) {
function next(err, ...args) {
if (err === false) return
if (err || taskIndex === tasks.length) {
return callback.apply(null, arguments);
return callback(err, ...args);
}
nextTask(slice(arguments, 1));
nextTask(args);
}

@@ -89,1 +87,3 @@

}
export default awaitify(waterfall)

@@ -1,6 +0,4 @@

import noop from 'lodash-es/noop';
import slice from './internal/slice';
import onlyOnce from './internal/onlyOnce';
import wrapAsync from './internal/wrapAsync';
import awaitify from './internal/awaitify';

@@ -16,3 +14,3 @@ /**

* @category Control Flow
* @param {Function} test - synchronous truth test to perform before each
* @param {AsyncFunction} test - asynchronous truth test to perform before each
* execution of `iteratee`. Invoked with ().

@@ -25,3 +23,3 @@ * @param {AsyncFunction} iteratee - An async function which is called each time

* callback. Invoked with (err, [results]);
* @returns undefined
* @returns {Promise} a promise, if no callback is passed
* @example

@@ -31,4 +29,4 @@ *

* async.whilst(
* function() { return count < 5; },
* function(callback) {
* function test(cb) { cb(null, count < 5;) },
* function iter(callback) {
* count++;

@@ -44,13 +42,24 @@ * setTimeout(function() {

*/
export default function whilst(test, iteratee, callback) {
callback = onlyOnce(callback || noop);
var _iteratee = wrapAsync(iteratee);
if (!test()) return callback(null);
var next = function(err/*, ...args*/) {
function whilst(test, iteratee, callback) {
callback = onlyOnce(callback);
var _fn = wrapAsync(iteratee);
var _test = wrapAsync(test);
var results
function next(err, ...rest) {
if (err) return callback(err);
if (test()) return _iteratee(next);
var args = slice(arguments, 1);
callback.apply(null, [null].concat(args));
};
_iteratee(next);
results = rest;
if (err === false) return;
_test(check);
}
function check(err, truth) {
if (err) return callback(err);
if (err === false) return;
if (!truth) return callback(null, ...results);
_fn(next);
}
return _test(check);
}
export default awaitify(whilst, 3)

@@ -1,4 +0,4 @@

import isObject from 'lodash-es/isObject';
import initialParams from './internal/initialParams';
import setImmediate from './internal/setImmediate';
import { isAsync } from './internal/wrapAsync'

@@ -62,2 +62,10 @@ /**

export default function asyncify(func) {
if (isAsync(func)) {
return function (...args/*, callback*/) {
const callback = args.pop()
const promise = func.apply(this, args)
return handlePromise(promise, callback)
}
}
return initialParams(function (args, callback) {

@@ -71,8 +79,4 @@ var result;

// if result is Promise object
if (isObject(result) && typeof result.then === 'function') {
result.then(function(value) {
invokeCallback(callback, null, value);
}, function(err) {
invokeCallback(callback, err.message ? err : new Error(err));
});
if (result && typeof result.then === 'function') {
return handlePromise(result, callback)
} else {

@@ -84,12 +88,16 @@ callback(null, result);

function handlePromise(promise, callback) {
return promise.then(value => {
invokeCallback(callback, null, value);
}, err => {
invokeCallback(callback, err && err.message ? err : new Error(err));
});
}
function invokeCallback(callback, error, value) {
try {
callback(error, value);
} catch (e) {
setImmediate(rethrow, e);
} catch (err) {
setImmediate(e => { throw e }, err);
}
}
function rethrow(error) {
throw error;
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc