Comparing version 2.6.0 to 3.0.0
13
index.js
@@ -386,5 +386,10 @@ var abbott = require('abbott'); | ||
var args = slice(arguments), | ||
done = args.pop(); | ||
done = args.pop(), | ||
result = fn.apply(null, args); | ||
done(null, fn.apply(null, args)); | ||
if(isResolvable(result)){ | ||
return righto.from(result)(done); | ||
} | ||
done(null, result); | ||
}].concat(slice(arguments, 1))); | ||
@@ -448,3 +453,5 @@ }; | ||
if(!isResolvable(value) && typeof value === 'function'){ | ||
value = value.apply(null, slice(arguments, 1)); | ||
return righto.all(slice(arguments, 1)).get(function(args){ | ||
return righto.from(value.apply(null, args)); | ||
}); | ||
} | ||
@@ -451,0 +458,0 @@ |
{ | ||
"name": "righto", | ||
"version": "2.6.0", | ||
"version": "3.0.0", | ||
"main": "index.js", | ||
@@ -5,0 +5,0 @@ "directories": { |
@@ -375,2 +375,4 @@ # Righto | ||
Eventuals can also be returned from inside righto.sync, which will be resolved within the flow. | ||
## From | ||
@@ -377,0 +379,0 @@ |
@@ -1130,2 +1130,37 @@ var test = require('tape'), | ||
test('sync return eventual', function(t){ | ||
t.plan(2); | ||
var stuff = righto.sync(function(){ | ||
return righto(function(done){ | ||
asyncify(function(){ | ||
done(null, 3); | ||
}); | ||
}); | ||
}); | ||
stuff(function(error, result){ | ||
t.notOk(error, 'no error'); | ||
t.equal(result, 3, 'Got correct result'); | ||
}); | ||
}); | ||
test('sync return erroring eventual', function(t){ | ||
t.plan(1); | ||
var stuff = righto.sync(function(){ | ||
return righto(function(done){ | ||
asyncify(function(){ | ||
done(true); | ||
}); | ||
}); | ||
}); | ||
stuff(function(error, result){ | ||
t.ok(error, 'got error'); | ||
}); | ||
}); | ||
test('sync errors throw', function(t){ | ||
@@ -1373,3 +1408,3 @@ t.plan(2); | ||
var x = righto.from(makeRighto, 5), | ||
y = righto.from(makeRighto, 10); | ||
y = righto.from(makePromise, 10); | ||
@@ -1382,2 +1417,44 @@ righto.mate(x, y)(function(error, x, y){ | ||
test('from tasks with eventual args', function(t){ | ||
t.plan(1); | ||
var x = righto(function(done){ | ||
done(null, 'x'); | ||
}); | ||
function makeRighto(a){ | ||
return righto(function(done){ | ||
done(null, a); | ||
}); | ||
} | ||
var result = righto.from(makeRighto, x); | ||
result(function(error, x){ | ||
t.equal(x, 'x'); | ||
}); | ||
}); | ||
test('from promise lazy executes', function(t){ | ||
t.plan(2); | ||
var ran; | ||
function makePromise(){ | ||
return new Promise(function(resolve){ | ||
ran = true; | ||
resolve(); | ||
}); | ||
} | ||
var result = righto.from(makePromise); | ||
t.notOk(ran, 'Promise has not run by now'); | ||
result(function(){ | ||
t.ok(ran, 'Promise has run by now'); | ||
}); | ||
}); | ||
test('isRighto', function(t){ | ||
@@ -1384,0 +1461,0 @@ t.plan(9); |
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
66397
1712
738