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

ee-async

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ee-async - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

4

index.js
require( "ee-error" );
require('ee-error');
module.exports = require( "./lib/async" );
module.exports = require('./lib/async');

@@ -5,5 +5,5 @@

module.exports = {
wait: require( "./wait" )
, each: require( "./each" )
, chain: require( "./chain" )
wait: require('./wait')
, each: require('./each')
, chain: require('./chain')
};
var each = require( "./each" )
, log = require( "ee-log" )
, type = require( "ee-types" );
var each = require('./each')
, log = require('ee-log')
, type = require('ee-types');
module.exports = function(){
var args = [ [] ], callback;
module.exports = function() {
var args = [[]], callback;
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){
if ( index === arr.length - 1 ){
if ( !type.function( arg ) ) throw new Error( "Last argument must be typeof «function»!" ).setName( "InvalidArgumentException" );
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr) {
if (index === arr.length - 1) {
if (!type.function(arg)) throw new Error('Last argument must be typeof «function»!').setName('InvalidArgumentException');
callback = arg;
}
else {
if ( type.function( arg ) ) args.push( arg );
else args[ 0 ].push( arg );
if (type.function(arg)) args.push(arg);
else args[0].push(arg);
}
} );
});
args.push( function( err, results ){
callback( err, results[ 0 ] );
} );
args.push(function(err, results) {
callback(err, results[0]);
});
each.apply( undefined, args );
each.apply(undefined, args);
};
var type = require( "ee-types" )
, log = require( "ee-log" );
var type = require('ee-types')
, log = require('ee-log');
var work = function( item, fn, index, next ){
var arg = item.result.concat( function(){
var work = function(item, fn, index, next) {
var arg = item.result.concat(function() {
item.result = [];
Array.prototype.slice.call( arguments, 0 ).every( function( arg, argIndex ){
if ( argIndex === 0 ){
if ( type.error( arg ) ) {
Array.prototype.slice.call(arguments, 0).every(function(arg, argIndex) {
if (argIndex === 0) {
if (type.error(arg)) {
item.result = arg;

@@ -19,11 +20,11 @@ return false;

}
else item.result.push( arg );
else item.result.push(arg);
return true;
} );
});
next( type.error( item.result ) );
} );
next(type.error(item.result));
});
fn.apply( undefined, arg );
fn.apply(undefined, arg);
};

@@ -34,11 +35,11 @@

var pipeline = function( item, workers, complete ){
var pipeline = function(item, workers, complete) {
var index = 0;
var doJob = function(){
work( item, workers[ index ], index, function( isError ){
var doJob = function() {
work(item, workers[index], index, function(isError) {
index++;
if ( index < workers.length && !isError ) doJob();
else complete( isError ? 0 : item.result.length, isError );
if (index < workers.length && !isError) doJob();
else complete(isError ? 0 : item.result.length, isError);
} );

@@ -53,30 +54,46 @@ }

module.exports = function(){
var items = [], workers = [], callback;
var items = []
, workers = []
, finished = 0
, maxLen = 0
, errCount = 0
, complete
, callback;
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){
if ( index === 0 ){
if ( !type.array( arg ) ) throw new Error( "Argument 0 must be typeof «array»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" );
items = arg.map( function( item ){ return { index: index, result: type.array( item ) ? item: [ item ] }; } );
// filter callback and input from worker functions
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr){
if (index === 0){
if (!type.array(arg)) throw new Error('Argument 0 must be typeof «array»! got «'+type( arg )+'»').setName('InvalidArgumentException');
items = arg.map(function(item){
return {
index: index
, result: type.array(item) ? item: [item]
};
});
}
else if ( index === arr.length - 1 ){
if ( !type.function( arg ) ) throw new Error( "Last argument must be typeof «function»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" );
else if (index === arr.length - 1) {
if (!type.function(arg)) throw new Error('Last argument must be typeof «function»! got «'+type( arg )+'»').setName('InvalidArgumentException');
callback = arg;
}
else {
if ( !type.function( arg ) ) throw new Error( "workers must be typeof «function»! got «"+type( arg )+"»" ).setName( "InvalidArgumentException" );
workers.push( arg );
if (!type.function(arg)) throw new Error('workers must be typeof «function»! got «'+type( arg )+'»').setName('InvalidArgumentException');
workers.push(arg);
}
} );
});
var finished = 0, maxLen = 0, errCount = 0, complete = function( argLen, hasError ){
if ( argLen > maxLen ) maxLen = argLen;
if ( hasError ) errCount++;
complete = function(argLen, hasError) {
var i = 0;
if ( ++finished === items.length ){
if (argLen > maxLen) maxLen = argLen;
if (hasError) errCount++;
items.sort( function( a, b ){ return a.index > b.index ? 1 : -1 } );
if (++finished === items.length) {
items = items.map( function( item ){
if ( maxLen <= 1 ) return type.array( item.result ) ? item.result[ 0 ] : item.result;
items.sort(function(a, b) {
return a.index > b.index ? 1 : -1
});
items = items.map(function(item) {
if (maxLen <= 1) return type.array(item.result) ? item.result[0] : item.result;
else return item.result;

@@ -86,4 +103,10 @@ } );

if ( errCount ) callback( new Error( "There were "+errCount+" errors while processing your data!" ).setName( "ProcessingError" ), items );
else callback( undefined, items );
if (errCount) {
i = items.length;
while(i--) {
if (item instanceof Error) return callback(item);
}
callback(new Error('There were '+errCount+' errors while processing your data!').setName('ProcessingError'), items);
}
else callback(undefined, items);
}

@@ -93,5 +116,5 @@ };

items.forEach( function( item, idx ){
pipeline( item, workers, complete );
} );
items.forEach(function(item, idx) {
pipeline(item, workers, complete);
});
}
var type = require( "ee-types" )
, log = require( "ee-log" );
var type = require('ee-types')
, log = require('ee-log');

@@ -9,38 +9,50 @@

module.exports = function(){
var jobs = [], callback, resLen = 0;
module.exports = function() {
var jobs = []
, resLen = 0
, results = []
, finished = 0
, errCount = 0
, complete
, callback;
Array.prototype.slice.call( arguments, 0 ).forEach( function( arg, index, arr ){
if ( !type.function( arg ) ) throw new Error( "Expected type «function», got «"+type( arg ) +"»!" ).setName( "InvalidArgumentException" );
if ( index === arr.length -1 ) callback = arg;
else jobs.push( arg );
} );
Array.prototype.slice.call(arguments, 0).forEach(function(arg, index, arr) {
if (!type.function(arg)) throw new Error('Expected type «function», got «'+type(arg)+'»!').setName('InvalidArgumentException');
if (index === arr.length -1) callback = arg;
else jobs.push(arg);
});
var results = [], finished = 0, errCount = 0, complete = function( index, args ){
complete = function(index, args) {
var i, a;
finished++;
if (args.length > 0) {
a = args[0];
if ( args.length > 0 ){
var a = args[ 0 ];
if (type.undefined(a) || type.null(a)) args.shift();
else if (type.error(a)) errCount++, args = args[0];
if ( type.undefined( a ) || type.null( a ) ) args.shift();
else if ( type.error( a ) ) errCount++, args = args[ 0 ];
if (args.length > resLen) resLen = args.length;
if ( args.length > resLen ) resLen = args.length;
results[ index ] = args;
results[index] = args;
}
if ( finished === jobs.length ) {
if ( resLen <= 1 ){
results = results.map( function( r ){
return type.array( r ) ? r[ 0 ] : r;
} );
if (finished === jobs.length) {
if (resLen <= 1) {
results = results.map(function(r) {
return type.array(r) ? r[0] : r;
});
}
if ( errCount > 0 ) callback( new Error( "There were "+errCount+" errors while processing your data!" ).setName( "ProcessingError" ), results );
else callback( undefined, results );
if (errCount) {
i = results.length;
while(i--) {
if (results instanceof Error) return callback(results);
}
callback(new Error('There were '+errCount+' errors while processing your data!').setName('ProcessingError'), results);
}
else callback(undefined, results);
}

@@ -50,7 +62,7 @@ }

jobs.forEach( function( job, index ){
job( function(){
complete( index, Array.prototype.slice.call( arguments, 0 ) );
} );
} );
jobs.forEach(function(job, index) {
job(function() {
complete(index, Array.prototype.slice.call(arguments, 0));
});
});
}
{
"name" : "ee-async"
, "description" : "simple control flow helpers"
, "version" : "0.1.0"
, "description" : "simpler control flow for asynchronous operations"
, "version" : "0.2.0"
, "homepage" : "https://github.com/eventEmitter/ee-async"

@@ -19,9 +19,9 @@ , "author" : "Michael van der Weg <michael@eventemitter.com> (http://eventemitter.com/)"

, "dependencies": {
"ee-types" : "*"
, "ee-log" : "*"
, "ee-error" : "*"
"ee-types" : "0.1.x"
, "ee-log" : "0.2.x"
, "ee-error" : "0.1.x"
}
, "devDependencies": {}
, "optionalDependencies": {}
, "keywords" : [ "asnc", "control-flow", "each", "chain", "wait" ]
, "keywords" : ["asnc", "control-flow", "each", "chain", "wait"]
, "scripts": {

@@ -28,0 +28,0 @@ "test" : "node test.js"

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