Comparing version 0.8.3 to 0.8.4
@@ -9,3 +9,25 @@ <!-- vim:ts=4:sts=4:sw=4:et:tw=60 --> | ||
Use ``nbind``. | ||
- WARNING: The deprecated ``deferred.node()`` interface will be | ||
removed. Use ``deferred.makeNodeResolver()``. | ||
## 0.8.4 | ||
- WARNING: ``promise.timeout`` is now rejected with an ``Error`` object | ||
and the message now includes the duration of the timeout in | ||
miliseconds. This doesn't constitute (in my opinion) a | ||
backward-incompatibility since it is a change of an undocumented and | ||
unspecified public behavior, but if you happened to depend on the | ||
exception being a string, you will need to revise your code. | ||
- Added ``deferred.makeNodeResolver()`` to replace the more cryptic | ||
``deferred.node()`` method. | ||
- Added experimental ``Q.promise(maker(resolve, reject))`` to make a | ||
promise inside a callback, such that thrown exceptions in the | ||
callback are converted and the resolver and rejecter are arguments. | ||
This is a shorthand for making a deferred directly and inspired by | ||
@gozala’s stream constructor pattern and the Microsoft Windows Metro | ||
Promise constructor interface. | ||
- Added experimental ``Q.begin()`` that is intended to kick off chains | ||
of ``.then`` so that each of these can be reordered without having to | ||
edit the new and former first step. | ||
## 0.8.3 | ||
@@ -12,0 +34,0 @@ |
{ | ||
"name": "q", | ||
"version": "0.8.3", | ||
"version": "0.8.4", | ||
"description": "A library for promises (CommonJS/Promises/A,B,D)", | ||
@@ -5,0 +5,0 @@ "homepage": "http://github.com/kriskowal/q/", |
51
q.js
@@ -204,4 +204,4 @@ // vim:ts=4:sts=4:sw=4: | ||
deferred.resolve = become; | ||
deferred.reject = function (reason) { | ||
return become(reject(reason)); | ||
deferred.reject = function (exception) { | ||
return become(reject(exception)); | ||
}; | ||
@@ -212,3 +212,4 @@ | ||
defer.prototype.node = function () { | ||
defer.prototype.node = // XXX deprecated | ||
defer.prototype.makeNodeResolver = function () { | ||
var self = this; | ||
@@ -226,2 +227,15 @@ return function (error, value) { | ||
exports.promise = promise; | ||
function promise(makePromise) { | ||
var deferred = defer(); | ||
call( | ||
makePromise, | ||
void 0, | ||
deferred.resolve, | ||
deferred.reject, | ||
deferred.progress | ||
).fail(deferred.reject); | ||
return deferred.promise; | ||
} | ||
/** | ||
@@ -361,6 +375,6 @@ * Constructs a Promise with a promise descriptor object and optional fallback | ||
* Constructs a rejected promise. | ||
* @param reason value describing the failure | ||
* @param exception value describing the failure | ||
*/ | ||
exports.reject = reject; | ||
function reject(reason) { | ||
function reject(exception) { | ||
var rejection = makePromise({ | ||
@@ -376,12 +390,12 @@ "when": function (rejected) { | ||
} | ||
return rejected ? rejected(reason) : reject(reason); | ||
return rejected ? rejected(exception) : reject(exception); | ||
} | ||
}, function fallback(op) { | ||
return reject(reason); | ||
return reject(exception); | ||
}, function valueOf() { | ||
return reject(reason); | ||
return reject(exception); | ||
}, true); | ||
// note that the error has not been handled | ||
rejections.push(rejection); | ||
errors.push(reason); | ||
errors.push(exception); | ||
return rejection; | ||
@@ -394,2 +408,3 @@ } | ||
*/ | ||
exports.begin = resolve; | ||
exports.resolve = resolve; | ||
@@ -531,3 +546,3 @@ exports.ref = resolve; // XXX deprecated | ||
* @param fulfilled function to be called with the fulfilled value | ||
* @param rejected function to be called with the rejection reason | ||
* @param rejected function to be called with the rejection exception | ||
* @return promise for the return value from the invoked callback | ||
@@ -549,5 +564,5 @@ */ | ||
function _rejected(reason) { | ||
function _rejected(exception) { | ||
try { | ||
return rejected ? rejected(reason) : reject(reason); | ||
return rejected ? rejected(exception) : reject(exception); | ||
} catch (exception) { | ||
@@ -568,3 +583,3 @@ return reject(exception); | ||
); | ||
}, function (reason) { | ||
}, function (exception) { | ||
if (done) { | ||
@@ -574,3 +589,3 @@ return; | ||
done = true; | ||
deferred.resolve(_rejected(reason)); | ||
deferred.resolve(_rejected(exception)); | ||
}); | ||
@@ -626,3 +641,3 @@ }); | ||
// when verb is "send", arg is a value | ||
// when verb is "throw", arg is a reason/error | ||
// when verb is "throw", arg is an exception | ||
function continuer(verb, arg) { | ||
@@ -871,5 +886,5 @@ var result; | ||
}); | ||
}, function (reason) { | ||
}, function (exception) { | ||
return when(callback(), function () { | ||
return reject(reason); | ||
return reject(exception); | ||
}); | ||
@@ -909,3 +924,3 @@ }); | ||
setTimeout(function () { | ||
deferred.reject("Timed out"); | ||
deferred.reject(new Error("Timed out after " + ms + "ms")); | ||
}, ms); | ||
@@ -912,0 +927,0 @@ return deferred.promise; |
@@ -474,3 +474,3 @@ [![Build Status](https://secure.travis-ci.org/kriskowal/q.png)](http://travis-ci.org/kriskowal/q) | ||
Q.when(delay(ms), function () { | ||
deferred.reject("Timed out"); | ||
deferred.reject(new Error("Timed out")); | ||
}); | ||
@@ -588,8 +588,8 @@ return deferred.promise; | ||
There is a ``node`` method on deferreds that is handy for the NodeJS | ||
callback pattern. | ||
There is a ``makeNodeResolver`` method on deferreds that is handy for | ||
the NodeJS callback pattern. | ||
```javascript | ||
var deferred = Q.defer(); | ||
FS.readFile("foo.txt", "utf-8", deferred.node()); | ||
FS.readFile("foo.txt", "utf-8", deferred.makeNodeResolver()); | ||
return deferred.promise; | ||
@@ -596,0 +596,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
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
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
167765
3710
1