New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

kgo

Package Overview
Dependencies
Maintainers
1
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 1.2.0 to 1.3.0

50

kgo.js

@@ -15,3 +15,3 @@ var run = require('./run'),

function kgoFn(name, dependencies, fn){
function kgoFn(){
if(inFlight){

@@ -21,3 +21,19 @@ throw "No tasks or defaults may be set after kgo is in flight";

if(arguments.length === 1 && name !== null && typeof name === 'object'){
var argIndex = 0;
while(typeof arguments[argIndex] === 'string'){
argIndex++;
}
var names = Array.prototype.slice.call(arguments, 0, argIndex),
dependencies,
fn;
if(!names.length){
names.push((returnlessId++).toString() + '__returnless');
}
if(typeof arguments[argIndex] === 'object' && !Array.isArray(arguments[argIndex])){
var defaults = arguments[argIndex];
if(defaultsDefined){

@@ -27,7 +43,7 @@ throw "Defaults may be defined only once per kgo";

for(var key in name){
for(var key in defaults){
if(key in tasks){
throw "A task is already defined for " + key;
}
results[key] = name[key];
results[key] = defaults[key];
}

@@ -38,24 +54,24 @@ defaultsDefined = true;

if(typeof name !== 'string'){
fn = dependencies;
dependencies = name;
name = (returnlessId++).toString() + '__returnless';
if(Array.isArray(arguments[argIndex])){
dependencies = arguments[argIndex];
argIndex++;
}
if(typeof dependencies === 'function'){
fn = dependencies;
dependencies = [];
if(typeof arguments[argIndex] === 'function'){
fn = arguments[argIndex];
}
if(typeof fn !== 'function'){
throw new Error('No function provided for task number ' + Object.keys(tasks).length + ' (' + name + ')');
throw new Error('No function provided for task number ' + Object.keys(tasks).length + ' (' + names + ')');
}
if(name in results){
throw "A default with the same name as this task (" + name + ") has already been set";
for(var i = 0; i < names.length; i++){
if(names[i] in results){
throw "A default with the same name as this task (" + names[i] + ") has already been set";
}
}
tasks[name] = {
name: name,
args: dependencies,
tasks[names] = {
names: names,
args: dependencies || [],
fn: fn

@@ -62,0 +78,0 @@ };

{
"name": "kgo",
"version": "1.2.0",
"version": "1.3.0",
"description": "Flow control the super easy way",

@@ -5,0 +5,0 @@ "main": "kgo.js",

@@ -148,2 +148,17 @@ kgo

## Multiple results
You can return more than one result in a single task by giving your task multiple names, and returning more results in the callback
kgo
('foo', 'bar', function(done){
done(null, 2, 4);
});
('baz', ['foo', 'bar'], function(foo, bar, done){
// foo === 2
// bar === 4
})
## Errors

@@ -150,0 +165,0 @@

var ignoreDependency = /^\!.+/;
function rotate90(array){
// transpose from http://www.codesuck.com/2012/02/transpose-javascript-array-in-one-line.html
return Object.keys(array[0]).map(function (c) { return array.map(function (r) { return r[c]; }); });
}
function Step(task, args, done){

@@ -15,4 +20,5 @@ this._task = task;

this._task.fn.apply(this, this._args.concat([function(error, result){
results.push(result);
this._task.fn.apply(this, this._args.concat([function(error){
var stepResults = Array.prototype.slice.call(arguments, 1);
results.push(stepResults);
step._runs++;

@@ -35,7 +41,7 @@ if(error){

}
this._done(null, this._parallel ? results : results[0]);
this._done(null, this._parallel ? rotate90(results) : results[0]);
};
function runTask(task, results, aboutToRun, done){
var name = task.name,
var names = task.names,
dependants = task.args,

@@ -64,7 +70,7 @@ taskFunction = task.fn,

var step = new Step(task, args, function(error, result){
done(name, error, result);
var step = new Step(task, args, function(error, results){
done(names, error, results);
});
aboutToRun(name);
aboutToRun(names);
step.run();

@@ -82,12 +88,15 @@ }

results,
function(name){
delete tasks[name];
function(names){
delete tasks[names];
},
function(name, error, result){
function(names, error, taskResults){
if(error){
emitter.emit('error', error, name);
emitter.emit('error', error, names);
return;
}
results[name] = result;
for(var i = 0; i < names.length; i++){
results[names[i]] = taskResults[i];
}
run(tasks, results, emitter);

@@ -94,0 +103,0 @@ }

var test = require('grape'),
kgo = require('../');
function doAsync(done, error, result){
function doAsync(done){
var args = Array.prototype.slice.call(arguments, 1);
setTimeout(function(){
done(error, result);
done.apply(null, args);
}, 100);

@@ -71,4 +72,4 @@ }

t.equal(stuff, 3);
}).on('error', function(error, name){
t.equal(name, 'stuff');
}).on('error', function(error, names){
t.equal(names[0], 'stuff');
t.equal(error.message, 'stuff screwed up');

@@ -183,2 +184,42 @@ });

}, 'cannot define defaults twice');
});
test('multiple datas', function(t){
t.plan(1);
kgo
('foo', 'bar', function(done){
done(null, 1,2);
})
(['foo'], function(foo, done){
t.equal(foo, 1);
});
(['bar'], function(bar, done){
t.equal(bar, 2);
});
});
test('multiple datas map-parallel', function(t){
t.plan(6);
var items = [1,2,3,4];
kgo
('items', function(done){
doAsync(done, null, items);
})
('doubled', 'trippled', ['items'], function(items, done){
this.count(items.length);
for(var i = 0; i < items.length; i++){
doAsync(done, null, items[i]*2, items[i]*3);
}
})
(['doubled', 'trippled'], function(doubled, trippled){
t.equal(doubled.length, 4);
t.equal(trippled.length, 4);
t.equal(doubled[0], 2);
t.equal(doubled[3], 8);
t.equal(trippled[0], 3);
t.equal(trippled[3], 12);
});
});
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