Comparing version 2.0.2 to 2.0.3
20
index.js
@@ -25,3 +25,3 @@ var isGeneratorFunction = require('is-generator-function') | ||
var done = false | ||
var nextQ = [] | ||
var ticking = false | ||
var callback | ||
@@ -62,11 +62,15 @@ | ||
// callback stepper with nextTick delay | ||
// nextQ to guarantee ordering | ||
function next () { | ||
var args = Array.prototype.slice.call(arguments) | ||
nextQ.push(args) | ||
process.nextTick(function () { | ||
while (nextQ.length) { | ||
step.apply(self, nextQ.shift()) | ||
} | ||
}) | ||
if (!ticking) { | ||
ticking = true | ||
process.nextTick(function () { | ||
ticking = false | ||
step.apply(self, args) | ||
}) | ||
} else { | ||
// if another next() called during pausing, | ||
// break iter and callback | ||
iter = null | ||
} | ||
} | ||
@@ -73,0 +77,0 @@ |
{ | ||
"name": "caco", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "Generator based control flow that supports both callbacks and promises", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -41,3 +41,3 @@ # caco | ||
return data | ||
... | ||
}).catch(function (err) { | ||
@@ -44,0 +44,0 @@ // handle uncaught error |
21
test.js
@@ -80,3 +80,3 @@ var test = require('tape') | ||
test('yieldable', function (t) { | ||
t.plan(4) | ||
t.plan(6) | ||
@@ -100,5 +100,12 @@ function * resolveGen (n) { | ||
}) | ||
caco(function * (next) { | ||
yield setTimeout(next, 0) | ||
var o = yield Observable | ||
var tryCatchNext = caco.wrap(function * (next) { | ||
try { | ||
return yield next(689) | ||
} catch (err) { | ||
t.equal(err, 689, 'try/catch next err') | ||
return yield next(null, 167) | ||
} | ||
}) | ||
var observ = function () { | ||
return Observable | ||
.fromArray([1, 2]) | ||
@@ -108,5 +115,9 @@ .merge(Observable.fromPromise(Promise.resolve(3))) | ||
.toArray() | ||
t.deepEqual(o, [1, 2, 3], 'yield observable') | ||
} | ||
caco(function * (next) { | ||
yield setTimeout(next, 0) | ||
t.deepEqual(yield observ(), [1, 2, 3], 'yield observable') | ||
t.equal(yield instantCb(next), 1044, 'yield callback') | ||
t.equal(yield tryCatch(), 167, 'yield gnerator-promise') | ||
t.equal(yield tryCatchNext(), 167, 'yield next val') | ||
}).catch(t.error) | ||
@@ -113,0 +124,0 @@ }) |
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
13758
313