This proposal specifies how progress is triggered and propagated in a Promises/A+ promise library.
The then method is the same as that specified in the promises-spec except that it also takes a third argument. We'll call that third argument the onProgress:
promise.then(onFulfilled, onRejected, onProgress)onProgressis an optional argument:- If
onProgressis not a function, it must be ignored.
- If
- If
onProgressis a function:- It must be called after progress is emitted, with the progress value as its first argument.
- The
onProgresscallback may return a promise.- The callback is not considered complete until the promise is fulfilled.
- The fulfillment value of the promise is the value to be propagated.
- If the promise is rejected, the rejection reason should be treated as if it was thrown by the callback directly.
- Unless the
onProgresscallback throws an exception with anameproperty equal to'StopProgressPropagation', the result of the function is used as the progress value to propagate. - If the
onProgresscallback throws an exception with anameproperty equal to'StopProgressPropagation', then the error is silenced. onProgressis never called once a promise has already been fulfilled or rejected.
resolver.progress(value)- The resolver has a
progressmethod.- It accepts a single
valueargument, which is the progress value. - If
valueis a promise, the progress value is the fulfillment value of the progress, and theonProgresscallbacks are only triggered when the promise is fulfilled.
- It accepts a single
- Calling
progresstriggers allonProgresscallbacks, passing the (fulfilled) progress value. progressreturns a promise.- If
valuewas a promise that got rejected, the returned promise is rejected with the rejection reason of that promise. - The returned promise is fulfilled with
undefinedonce all progress callbacks are complete, - or is rejected with the first (non-
StopProgressPropagation) exception thrown by the callbacks, if any.
- If