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

kgo

Package Overview
Dependencies
Maintainers
2
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kgo - npm Package Compare versions

Comparing version 2.0.5 to 2.1.0

5

package.json
{
"name": "kgo",
"version": "2.0.5",
"version": "2.1.0",
"description": "Flow control the super easy way",
"main": "kgo.js",
"scripts": {
"test": "node test"
"test": "node test",
"watch": "watchify test/index.js -o test/index.browser.js -d"
},

@@ -9,0 +10,0 @@ "author": "Kory Nunn <knunn187@gmail.com>",

60

run.js

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

var ignoreDependency = /^\!.+/;
var ignoreDependency = /^\!.+/,
errorTask = '*error';

@@ -29,12 +30,34 @@ function Step(task, args, done){

function runTask(task, results, aboutToRun, done){
function runTask(task, results, aboutToRun, done, error){
var names = task.names,
dependants = task.args,
args = [];
args = [],
passError;
if(dependants){
var useError = dependants[0] === errorTask;
if(useError && !error && dependants.length === 1){
return;
}
for(var i = 0; i < dependants.length; i++) {
var dependantName = dependants[i],
var isErrorDep = dependants[i] === errorTask,
dependantName = dependants[i],
ignore = dependantName.match(ignoreDependency);
if(isErrorDep){
args.push(error);
continue;
}
if(useError && error){
args.push(undefined);
continue;
}
if(error){
return;
}
if(ignore){

@@ -62,3 +85,3 @@ dependantName = dependantName.slice(1);

function run(tasks, results, emitter){
function run(tasks, results, emitter, error){
var currentTask,

@@ -83,9 +106,10 @@ noMoreTasks = true;

},
function(names, error, taskResults){
function(names, taskError, taskResults){
if(emitter._complete){
return;
}
if(error){
if(taskError){
run(tasks, results, emitter, taskError);
emitter._complete = true;
emitter.emit('error', error, names);
emitter.emit('error', taskError, names);
emitter.emit('complete');

@@ -100,3 +124,4 @@ return;

run(tasks, results, emitter);
}
},
error
);

@@ -112,12 +137,15 @@ }

function cloneAndRun(tasks, results, emitter){
var todo = {};
var todo = {},
hasErrorTask;
emitter._taskCount = Object.keys(results).length;
function checkDependencyIsDefined(dependencyName){
function checkDependencyIsDefined(result, dependencyName){
dependencyName = dependencyName.match(/\!?(.*)/)[1];
if(!(dependencyName in tasks) && !(dependencyName in results)){
throw new Error('No task or result has been defined for dependency: ' + dependencyName);
if(dependencyName !== errorTask && !(dependencyName in tasks) && !(dependencyName in results)){
throw new Error('No task or result has been defined for dependency: ' + dependencyName);
}
return result || dependencyName === errorTask;
}

@@ -129,5 +157,9 @@

tasks[key].args.map(checkDependencyIsDefined);
hasErrorTask = tasks[key].args.reduce(checkDependencyIsDefined, false) || hasErrorTask;
}
if(hasErrorTask){
emitter.on('error', function(){});
}
run(todo, results, emitter);

@@ -134,0 +166,0 @@ }

@@ -55,10 +55,14 @@ var test = require('tape'),

kgo('things', function(done){
kgo
('things', function(done){
doAsync(done, null, 1);
})('stuff', ['things'], function(things, done){
})
('stuff', ['things'], function(things, done){
done(new Error('stuff screwed up'));
})(['stuff'], function(stuff, done){
})
(['stuff'], function(stuff, done){
t.equal(stuff, 3);
done();
}).on('error', function(error, names){
})
.on('error', function(error, names){
t.equal(names[0], 'stuff');

@@ -264,2 +268,136 @@ t.equal(error.message, 'stuff screwed up');

test('error handler pass', function(t){
t.plan(2);
kgo
('result', function(done){
setTimeout(function(){
done(null, true);
}, 100);
})
(['*error', 'result'], function(error, result){
t.notOk(error);
t.ok(result);
});
});
test('error handler fail', function(t){
t.plan(2);
kgo
('result', function(done){
setTimeout(function(){
done(true);
}, 100);
})
(['*error', 'result'], function(error, result){
t.ok(error);
t.notOk(result);
});
});
test('error handler fail different step', function(t){
t.plan(4);
kgo
('initial', function(done){
setTimeout(function(){
done(null, true);
}, 100);
})
('result', ['initial'], function(initial, done){
setTimeout(function(){
done(true);
}, 100);
})
(['*error', 'initial'], function(error, initial){
t.ok(initial);
t.notOk(error);
})
(['*error', 'result'], function(error, result){
t.ok(error);
t.notOk(result);
});
});
test('error handler fail not passed successful results', function(t){
t.plan(3);
kgo
('initial', function(done){
setTimeout(function(){
done(null, true);
}, 100);
})
('result', ['initial'], function(initial, done){
setTimeout(function(){
done(true);
}, 100);
})
(['*error', 'initial', 'result'], function(error, initial, result){
t.ok(error);
t.notOk(initial);
t.notOk(result);
});
});
test('multiple error handlers', function(t){
t.plan(2);
kgo
('result', function(done){
setTimeout(function(){
done(true);
}, 100);
})
(['*error', 'result'], function(error, result){
t.ok(error, 'result handler got error');
})
(['*error'], function(error){
t.ok(error, 'error only handler got error');
});
});
test('generic error handlers', function(t){
t.plan(1);
kgo
('initial', function(done){
setTimeout(function(){
done(null, true);
}, 100);
})
('result', ['initial'], function(initial, done){
setTimeout(function(){
done(null, initial);
}, 100);
})
(['result'], function(result){
t.ok(result);
})
(['*error'], function(error){
t.fail();
});
});
test('complete style error handling', function(t){
t.plan(2);
kgo
('initial', function(done){
setTimeout(function(){
done(null, true);
}, 100);
})
('result', ['initial'], function(initial, done){
setTimeout(function(){
done(null, initial);
}, 100);
})
(['*error', '!result'], function(error, shouldBeDoneFn){
t.notOk(error);
t.equal(typeof shouldBeDoneFn, 'function');
});
});
test('stupid dep list', function(t){

@@ -266,0 +404,0 @@ t.plan(1);

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