Commit 083f8f7a authored by Tristan Cavelier's avatar Tristan Cavelier

Promise.js error static method manage promise parameter

parent d204822f
......@@ -50,22 +50,28 @@ Promise.when = function (item, onSuccess, onError, onProgress) {
};
/**
* error(value, [onError]): Promise
* error(item, [onError]): Promise
*
* Return value as first parameter of the promise answer. The method returns a
* Return an item as first parameter of the promise answer. The method returns a
* rejected promise.
*
* Promise.error('a').then(null, console.log); // shows 'a'
* Promise.error(Promise.when('a')).then(null, console.log); // shows 'a'
*
* @method error
* @static
* @param {Any} value The value to use
* @param {Any} item The item 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);
Promise.error = function (item, onError) {
var p = new Promise().fail(onError), solver = p.defer();
Promise.when(
item,
solver.reject.bind(solver),
solver.reject.bind(solver),
solver.notify.bind(solver)
);
return p;
};
......
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