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

async-es

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

async-es - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

@@ -233,3 +233,3 @@ import arrayEach from 'lodash-es/_arrayEach';

arrayEach(getDependents(currentTask), function (dependent) {
if (!(--uncheckedDependencies[dependent])) {
if (--uncheckedDependencies[dependent] === 0) {
readyToCheck.push(dependent);

@@ -236,0 +236,0 @@ }

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

# v2.0.1
- Significantly optimized all iteration based collection methods such as `each`, `map`, `filter`, etc (#1245, #1246, #1247).
# v2.0.0

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

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

import eachLimit from './eachLimit';
import doLimit from './internal/doLimit';
import eachOf from './eachOf';
import withoutIndex from './internal/withoutIndex';

@@ -63,2 +63,4 @@ /**

*/
export default doLimit(eachLimit, Infinity);
export default function eachLimit(coll, iteratee, callback) {
eachOf(coll, withoutIndex(iteratee), callback);
}

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

import isArrayLike from 'lodash-es/isArrayLike';
import eachOfLimit from './eachOfLimit';
import doLimit from './internal/doLimit';
import noop from 'lodash-es/noop';
import once from 'lodash-es/once';
import onlyOnce from './internal/onlyOnce';
// eachOf implementation optimized for array-likes
function eachOfArrayLike(coll, iteratee, callback) {
callback = once(callback || noop);
var index = 0,
completed = 0,
length = coll.length;
if (length === 0) {
callback(null);
}
function iteratorCallback(err) {
if (err) {
callback(err);
} else if (++completed === length) {
callback(null);
}
}
for (; index < length; index++) {
iteratee(coll[index], index, onlyOnce(iteratorCallback));
}
}
// a generic version of eachOf which can handle array, object, and iterator cases.
var eachOfGeneric = doLimit(eachOfLimit, Infinity);
/**

@@ -45,2 +76,5 @@ * Like [`each`]{@link module:Collections.each}, except that it passes the key (or index) as the second argument

*/
export default doLimit(eachOfLimit, Infinity);
export default function(coll, iteratee, callback) {
var eachOfImplementation = isArrayLike(coll) ? eachOfArrayLike : eachOfGeneric;
eachOfImplementation(coll, iteratee, callback);
}

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

import everyLimit from './everyLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOf from './eachOf';
import notId from './internal/notId';

@@ -32,2 +33,2 @@ /**

*/
export default doLimit(everyLimit, Infinity);
export default createTester(eachOf, notId, notId);

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

import filterLimit from './filterLimit';
import doLimit from './internal/doLimit';
import filter from './internal/filter';
import doParallel from './internal/doParallel';

@@ -31,2 +31,2 @@ /**

*/
export default doLimit(filterLimit, Infinity);
export default doParallel(filter);

@@ -10,17 +10,25 @@ import noop from 'lodash-es/noop';

callback = once(callback || noop);
obj = obj || [];
var nextElem = iterator(obj);
if (limit <= 0) {
if (limit <= 0 || !obj) {
return callback(null);
}
var nextElem = iterator(obj);
var done = false;
var running = 0;
var errored = false;
(function replenish () {
if (done && running <= 0) {
function iterateeCallback(err) {
running -= 1;
if (err) {
done = true;
callback(err);
}
else if (done && running <= 0) {
return callback(null);
}
else {
replenish();
}
}
while (running < limit && !errored) {
function replenish () {
while (running < limit && !done) {
var elem = nextElem();

@@ -35,16 +43,8 @@ if (elem === null) {

running += 1;
/* eslint {no-loop-func: 0} */
iteratee(elem.value, elem.key, onlyOnce(function (err) {
running -= 1;
if (err) {
callback(err);
errored = true;
}
else {
replenish();
}
}));
iteratee(elem.value, elem.key, onlyOnce(iterateeCallback));
}
})();
}
replenish();
};
}

@@ -5,31 +5,38 @@ import isArrayLike from 'lodash-es/isArrayLike';

export default function iterator(coll) {
function createArrayIterator(coll) {
var i = -1;
var len;
if (isArrayLike(coll)) {
len = coll.length;
return function next() {
i++;
return i < len ? {value: coll[i], key: i} : null;
};
var len = coll.length;
return function next() {
return ++i < len ? {value: coll[i], key: i} : null;
}
}
var iterate = getIterator(coll);
if (iterate) {
return function next() {
var item = iterate.next();
if (item.done)
return null;
i++;
return {value: item.value, key: i};
};
function createES2015Iterator(iterator) {
var i = -1;
return function next() {
var item = iterator.next();
if (item.done)
return null;
i++;
return {value: item.value, key: i};
}
}
var okeys = keys(coll);
len = okeys.length;
function createObjectIterator(obj) {
var okeys = keys(obj);
var i = -1;
var len = okeys.length;
return function next() {
i++;
var key = okeys[i];
return i < len ? {value: coll[key], key: key} : null;
var key = okeys[++i];
return i < len ? {value: obj[key], key: key} : null;
};
}
export default function iterator(coll) {
if (isArrayLike(coll)) {
return createArrayIterator(coll);
}
var iterator = getIterator(coll);
return iterator ? createES2015Iterator(iterator) : createObjectIterator(coll);
}

@@ -18,3 +18,3 @@ import arrayEach from 'lodash-es/_arrayEach';

function _insert(data, pos, callback) {
function _insert(data, insertAtFront, callback) {
if (callback != null && typeof callback !== 'function') {

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

if (pos) {
if (insertAtFront) {
q._tasks.unshift(item);

@@ -42,0 +42,0 @@ } else {

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

import mapLimit from './mapLimit';
import doLimit from './internal/doLimit';
import doParallel from './internal/doParallel';
import map from './internal/map';

@@ -40,2 +40,2 @@ /**

*/
export default doLimit(mapLimit, Infinity);
export default doParallel(map);
{
"name": "async-es",
"description": "Higher-order functions and common patterns for asynchronous code",
"version": "2.0.0",
"version": "2.0.1",
"main": "index.js",

@@ -6,0 +6,0 @@ "author": "Caolan McMahon",

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

import parallelLimit from './parallelLimit';
import doLimit from './internal/doLimit';
import eachOf from './eachOf';
import parallel from './internal/parallel';

@@ -70,2 +70,4 @@ /**

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

@@ -9,4 +9,4 @@ import queue from './internal/queue';

* waiting to be processed. Invoke with `queue.length()`.
* @property {Function} started - a function returning whether or not any
* items have been pushed and processed by the queue. Invoke with `queue.started()`.
* @property {boolean} started - a boolean indicating whether or not any
* items have been pushed and processed by the queue.
* @property {Function} running - a function returning the number of items

@@ -13,0 +13,0 @@ * currently being processed. Invoke with `queue.running()`.

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

import rejectLimit from './rejectLimit';
import doLimit from './internal/doLimit';
import reject from './internal/reject';
import doParallel from './internal/doParallel';

@@ -30,2 +30,2 @@ /**

*/
export default doLimit(rejectLimit, Infinity);
export default doParallel(reject);

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

import someLimit from './someLimit';
import doLimit from './internal/doLimit';
import createTester from './internal/createTester';
import eachOf from './eachOf';
import identity from 'lodash-es/identity';

@@ -34,2 +35,2 @@ /**

*/
export default doLimit(someLimit, Infinity);
export default createTester(eachOf, Boolean, identity);