Comparing version 1.6.1 to 1.7.0
28
index.js
@@ -82,8 +82,14 @@ var foreign = require('foreign'), | ||
errored, | ||
generator = fn.apply(null, args.concat(function(error){ | ||
errored = true; | ||
callback(error); | ||
})), | ||
lastValue; | ||
function reject(error){ | ||
if(errored){ | ||
return; | ||
} | ||
errored = true; | ||
callback(error); | ||
} | ||
var generator = fn.apply(null, args.concat(reject)); | ||
function run(){ | ||
@@ -95,2 +101,5 @@ if(errored){ | ||
if(next.done){ | ||
if(errored){ | ||
return; | ||
} | ||
return callback(null, next.value); | ||
@@ -104,4 +113,3 @@ } | ||
if(error){ | ||
errored = true; | ||
callback(error); | ||
reject(error); | ||
} | ||
@@ -259,2 +267,9 @@ }); | ||
righto.value = function(){ | ||
var args = arguments; | ||
return righto(function(done){ | ||
done.apply(null, [null].concat(slice(args))); | ||
}); | ||
}; | ||
righto.proxy = function(){ | ||
@@ -267,2 +282,3 @@ if(typeof Proxy === 'undefined'){ | ||
}; | ||
for(var key in righto){ | ||
@@ -269,0 +285,0 @@ righto.proxy[key] = righto[key]; |
{ | ||
"name": "righto", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -204,2 +204,59 @@ # Righto | ||
## All | ||
righto.all takes N tasks, or an Array of tasks as the first argument, resolves them all | ||
in parallel, and results in an Array of results. | ||
```javascript | ||
var task1 = righto(function(done){ | ||
setTimeout(function(){ | ||
done(null, 'a'); | ||
}, 1000); | ||
}); | ||
var task2 = righto(function(done){ | ||
setTimeout(function(){ | ||
done(null, 'b'); | ||
}, 1000); | ||
}); | ||
var task3 = righto(function(done){ | ||
setTimeout(function(){ | ||
done(null, 'c'); | ||
}, 1000); | ||
}); | ||
var all = righto.all([task1, task2, task3]); | ||
all(function(error, results){ | ||
results; // -> ['a','b','c'] | ||
}); | ||
``` | ||
## Value (passing resolveables as unresolved arguments) | ||
Sometimes it may be required to pass a resolveable (a righto, or promise) without as an argument, | ||
rather than passing the resolved value of the resolvable. you can do this using `righto.value(resolvable)` | ||
```javascript | ||
var righto1 = righto(function(done){ | ||
done(null, 5); | ||
}); | ||
var rightoValue = righto.value(righto1); | ||
var righto2 = righto(function(value, done){ | ||
// value === righto1 | ||
value(function(error, x){ | ||
// x === 5; | ||
}); | ||
}, rightoValue); | ||
righto2(); | ||
``` | ||
## Subkeys | ||
@@ -206,0 +263,0 @@ |
@@ -701,1 +701,22 @@ var test = require('tape'), | ||
}); | ||
test('righto.value', function(t){ | ||
t.plan(2); | ||
var righto1 = righto(function(done){ | ||
done(null, 5); | ||
}); | ||
var rightoValue = righto.value(righto1); | ||
var righto2 = righto(function(value, done){ | ||
t.notEqual(value, 5); | ||
value(function(error, x){ | ||
t.equal(x, 5); | ||
}); | ||
}, rightoValue); | ||
righto2(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
575871
8533
423