Comparing version 2.1.1 to 2.2.0
@@ -5,3 +5,3 @@ /** | ||
var assert = require('assert'); | ||
// var assert = require('assert'); | ||
var _ = require('@sailshq/lodash'); | ||
@@ -161,4 +161,14 @@ var bluebird = require('bluebird'); | ||
self._hasFinishedExecuting = true; | ||
return cb(undefined, result); | ||
// If there are any extra arguments, send them back too. | ||
// (This is unconventional, but permitted to allow for extra metadata, | ||
// which is sometimes handy when you want to expose advanced usage.) | ||
if (arguments.length > 2) { | ||
return cb.apply(undefined, Array.prototype.slice.call(arguments)); | ||
} | ||
// Otherwise, this is the normal case. | ||
else { | ||
return cb(undefined, result); | ||
} | ||
}); | ||
@@ -223,6 +233,9 @@ } catch (e) { | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// FUTURE: Use cached promise, if one has already been created | ||
// (potentially improves perf of `.catch()`) | ||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
// Use cached promise, if one has already been created. | ||
// | ||
// > This prevents extraneous invocation in `.then()` chains. | ||
// > (& potentially improves perf of `.catch()`) | ||
if (this._promise) { | ||
return this._promise; | ||
}//-• | ||
@@ -237,4 +250,6 @@ // Build a function that, when called, will begin executing the underlying | ||
var promise = getPromise(); | ||
return promise; | ||
// Make a promise, and cache it as `this._promise` so that it can be | ||
// reused (e.g. in case there are multiple calls to `.then()` and `.catch()`) | ||
this._promise = getPromise(); | ||
return this._promise; | ||
@@ -241,0 +256,0 @@ }; |
{ | ||
"name": "parley", | ||
"version": "2.1.1", | ||
"version": "2.2.0", | ||
"description": "Practical, lightweight flow control for Node.js. Supports callbacks and promises.", | ||
@@ -5,0 +5,0 @@ "main": "lib/parley.js", |
@@ -519,2 +519,8 @@ parley | ||
## Pronunciation | ||
[`/ˈpärlē/`](http://www.macmillandictionary.com/us/pronunciation/american/parley) | ||
> _Rather than picking barley and getting snarly, she decided to `npm install parley` and listen to some Bob Marley._ | ||
## License | ||
@@ -521,0 +527,0 @@ |
@@ -112,33 +112,18 @@ /** | ||
var deferred; before(function(){ deferred = parley(function(done){ setTimeout(function (){ return done(undefined, 'hello!'); }, 12); }); }); | ||
it('should ignore subsequent calls', function(done){ | ||
it('should do the normal promise chaining thing', function(done){ | ||
this.slow(300); | ||
// As a hack, override console.warn(). | ||
// (this is mainly to improve the experience of looking at test results, | ||
// but it also has the benefit of adding another check.) | ||
var origConsoleWarn = global.console.warn; | ||
var counter = 0; | ||
global.console.warn = function(){ | ||
counter++; | ||
}; | ||
deferred.then(function (){ | ||
setTimeout(function (){ | ||
global.console.warn = origConsoleWarn; | ||
try { | ||
assert.equal(counter, 3); | ||
} catch(e) { return done(e); } | ||
return done(); | ||
}, 125); | ||
// do nothing | ||
}).catch(function(err){ return done(err); }); | ||
// The following .then() calls will be ignored. | ||
// (Note that 3 extra warnings will be logged, though.) | ||
// The following .then() calls will all run in order. | ||
deferred.then(function (){ | ||
return done(new Error('Should never make it here')); | ||
// do nothing | ||
}).catch(function(err){ return done(err); }); | ||
deferred.then(function (){ | ||
return done(new Error('Should never make it here')); | ||
// do nothing | ||
}).catch(function(err){ return done(err); }); | ||
deferred.then(function (){ | ||
return done(new Error('Should never make it here')); | ||
return done(); | ||
}).catch(function(err){ return done(err); }); | ||
@@ -145,0 +130,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
113067
530
1604