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) { ...@@ -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. * rejected promise.
* *
* Promise.error('a').then(null, console.log); // shows 'a' * Promise.error('a').then(null, console.log); // shows 'a'
* Promise.error(Promise.when('a')).then(null, console.log); // shows 'a'
* *
* @method error * @method error
* @static * @static
* @param {Any} value The value to use * @param {Any} item The item to use
* @param {Function} [onError] the callback called on error * @param {Function} [onError] the callback called on error
* @return {Promise} The promise * @return {Promise} The promise
*/ */
Promise.error = function (value, onError) { Promise.error = function (item, onError) {
var p = new Promise().fail(onError); var p = new Promise().fail(onError), solver = p.defer();
p.defer().reject(value); Promise.when(
item,
solver.reject.bind(solver),
solver.reject.bind(solver),
solver.notify.bind(solver)
);
return p; 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