Commit 544b9ac3 authored by Tristan Cavelier's avatar Tristan Cavelier

Promise.js when onProgress callback added and assign callback(s) to item

parent 469cb81b
......@@ -21,7 +21,7 @@ function Promise() {
// when(value, callback, errback_opt)
/**
* when(item, [onSuccess], [onError]): Promise
* when(item, [onSuccess], [onError], [onProgress]): Promise
*
* Return an item as first parameter of the promise answer. If item is of
* type Promise, the method will just return the promise. If item is of type
......@@ -34,16 +34,17 @@ function Promise() {
* @param {Any} item The item to use
* @param {Function} [onSuccess] The callback called on success
* @param {Function} [onError] the callback called on error
* @param {Function} [onProgress] the callback called on progress
* @return {Promise} The promise
*/
Promise.when = function (item, onSuccess, onError) {
Promise.when = function (item, onSuccess, onError, onProgress) {
if (item instanceof Promise) {
return item;
return item.done(onSuccess).fail(onError).progress(onProgress);
}
if (typeof Deferred === 'function' && item instanceof Deferred) {
return item.promise();
return item.promise().done(onSuccess).fail(onError).progress(onProgress);
}
var p = new Promise().done(onSuccess).fail(onError);
var p = new Promise().done(onSuccess).fail(onError).progress(onProgress);
p.defer().resolve(item);
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