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)
onProgress
is an optional argument:- If
onProgress
is not a function, it must be ignored.
- If
- If
onProgress
is a function:- It must be called after progress is emitted, with the progress value as its first argument.
- The
onProgress
callback 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
onProgress
callback throws an exception with aname
property equal to'StopProgressPropagation'
, the result of the function is used as the progress value to propagate. - If the
onProgress
callback throws an exception with aname
property equal to'StopProgressPropagation'
, then the error is silenced. onProgress
is never called once a promise has already been fulfilled or rejected.
resolver.progress(value)
- The resolver has a
progress
method.- It accepts a single
value
argument, which is the progress value. - If
value
is a promise, the progress value is the fulfillment value of the progress, and theonProgress
callbacks are only triggered when the promise is fulfilled.
- It accepts a single
- Calling
progress
triggers allonProgress
callbacks, passing the (fulfilled) progress value. progress
returns a promise.- If
value
was a promise that got rejected, the returned promise is rejected with the rejection reason of that promise. - The returned promise is fulfilled with
undefined
once all progress callbacks are complete, - or is rejected with the first (non-
StopProgressPropagation
) exception thrown by the callbacks, if any.
- If