Commit 4d9ba91a authored by Tristan Cavelier's avatar Tristan Cavelier

Promise.js error added

parent 787caa79
......@@ -49,6 +49,26 @@ Promise.when = function (item, onSuccess, onError, onProgress) {
return p;
};
/**
* error(value, [onError]): Promise
*
* Return value as first parameter of the promise answer. The method returns a
* rejected promise.
*
* Promise.error('a').then(null, console.log); // shows 'a'
*
* @method error
* @static
* @param {Any} value The value to use
* @param {Function} [onError] the callback called on error
* @return {Promise} The promise
*/
Promise.error = function (value, onError) {
var p = new Promise().fail(onError);
p.defer().reject(value);
return p;
};
////////////////////////////////////////////////////////////
// http://wiki.commonjs.org/wiki/Promises/B
// get(object, name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment