laissez-faire
Advanced tools
Comparing version 0.8.1 to 0.8.2
{ | ||
"name": "laissez-faire", | ||
"version": "0.8.1", | ||
"version": "0.8.2", | ||
"description": "A promise implementation. Simple and fast", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
@@ -7,4 +7,9 @@ exports = module.exports = Promise | ||
* var promise = new Promise | ||
* fs.readFile('/files.js', function(err, src){ | ||
* if (err) promise.reject(err) | ||
* else promise.fulfill(src.toString()) | ||
* }) | ||
* return promise | ||
*/ | ||
function Promise () {this._len = 0} | ||
function Promise (fn) {this._len = 0} | ||
@@ -58,3 +63,3 @@ var proto = Promise.prototype | ||
* @param {Function} fn the handler to apply | ||
* @param {Any} value | ||
* @param {Any} value | ||
* @api private | ||
@@ -99,2 +104,3 @@ */ | ||
case 'pending': | ||
// create a dummy promise | ||
this[this._len++] = { | ||
@@ -104,3 +110,3 @@ // Handlers are bound to the assignment properties since these aren't run inside a try catch. Having no handlers is fine, the values will just pass straight through to the resolvers. | ||
// Interestingly if we didn't provide an error thrower as a backup we would still be guaranteed to throw at the right time. However it would be "no such method" instead of the users error. | ||
reject: fail || function (e) {throw e} | ||
reject: fail || thrower | ||
} | ||
@@ -119,2 +125,5 @@ break | ||
function thrower (e) {throw e} | ||
function noop () {} | ||
/** | ||
@@ -126,4 +135,4 @@ * Give the promise it's value and propogate it to its pending children | ||
* one.resolve('sandy') | ||
* one.then(function(value) {value === 'sandy'}) -> true | ||
* two.then(function(value) {value === 'sandy'}) -> true | ||
* one.then(function(value) {value === 'sandy'}) //=> true | ||
* two.then(function(value) {value === 'sandy'}) //=> true | ||
* | ||
@@ -156,3 +165,3 @@ * @param {!Error} value Can be anything other than an Error | ||
* | ||
* @param {Error} e The reason for rejection | ||
* @param {Any} e The reason for rejection | ||
* @return {Self} | ||
@@ -232,3 +241,3 @@ */ | ||
* var promise = new Promise().resolve('bang') | ||
* promsie.valueOf() === 'bang' => true | ||
* promsie.valueOf() === 'bang' // => true | ||
* | ||
@@ -385,4 +394,2 @@ * @param {Function} done optional | ||
function noop () {} | ||
/** | ||
@@ -397,2 +404,23 @@ * Ducktype test if an object is a promise | ||
/* | ||
* Create a pending promise without new | ||
* | ||
* var defer = Promise.pending | ||
* return defer(function(promise){ | ||
* fs.readFile('/files.js', function(err, src){ | ||
* if (err) promise.reject(err) | ||
* else promise.fulfill(src.toString()) | ||
* }) | ||
* }) | ||
* | ||
* @param {Function} to be run in the context of the new promise | ||
* @return {Promise} | ||
*/ | ||
exports.pending = newPending | ||
function newPending (fn) { | ||
var promise = new Promise | ||
if (fn) fn.call(promise, promise) | ||
return promise | ||
} | ||
/** | ||
@@ -428,15 +456,21 @@ * Helper to quickly create a rejected promise | ||
* Dafualt uncought error handler. It will wait 1 second for you to | ||
* handle the error before rethrowing it. Feel free to replace | ||
* this function with one you find more useful. Its purely a debugging | ||
* feature. Technically promises shouldn't ever throw since at any time in the | ||
* future someone could decide to handle the error | ||
* handle the error before rethrowing it if its an Error instance or simple | ||
* logging it otherwise. Feel free to replace this function with one you | ||
* find more useful. Its purely a debugging feature. Technically promises | ||
* shouldn't ever throw since at any time in the future someone could decide | ||
* to handle the error. To void this behaviour: | ||
* | ||
* Promise.onError = null | ||
* | ||
* @param {Promise} promise The promise that was rejected without an error handler | ||
* @param {Error} e The error emitted by the promise | ||
* @param {Promise} promise, which was rejected without an error handler | ||
* @param {Any} error, the reason for rejection | ||
*/ | ||
exports.onError = function (promise, e) { | ||
exports.onError = function (promise, error) { | ||
promise._throw = setTimeout(function () { | ||
if (e instanceof Error) | ||
e.message += ' (Rethrown from rejected promise)' | ||
throw e | ||
if (error instanceof Error) { | ||
error.message += ' (Rethrown from rejected promise)' | ||
throw error | ||
} else { | ||
console && console.warn(error) | ||
} | ||
}, 1000) | ||
@@ -448,5 +482,7 @@ } | ||
* in the onCatch handler. This will be called when an error handler is added to | ||
* a rejected promise. | ||
* a rejected promise. To void this behaviour: | ||
* | ||
* Promise.onCatch = null | ||
* | ||
* @param {Promise} promise The promise which previously failed without error handlers | ||
* @param {Promise} promise, which previously failed without error handlers | ||
*/ | ||
@@ -453,0 +489,0 @@ exports.onCatch = function (promise) { |
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
0
12746
2
446
2
0