|
26 | 26 | * // since this fn executes async in a future turn of the event loop, we need to wrap
|
27 | 27 | * // our code into an $apply call so that the model changes are properly observed.
|
28 | 28 | * scope.$apply(function() {
|
| 29 | + * deferred.notify('About to greet ' + name + '.'); |
| 30 | + * |
29 | 31 | * if (okToGreet(name)) {
|
30 | 32 | * deferred.resolve('Hello, ' + name + '!');
|
31 | 33 | * } else {
|
|
42 | 44 | * alert('Success: ' + greeting);
|
43 | 45 | * }, function(reason) {
|
44 | 46 | * alert('Failed: ' + reason);
|
| 47 | + * }, function(update) { |
| 48 | + * alert('Got notification: ' + update); |
45 | 49 | * });
|
46 | 50 | * </pre>
|
47 | 51 | *
|
|
60 | 64 | * A new instance of deferred is constructed by calling `$q.defer()`.
|
61 | 65 | *
|
62 | 66 | * The purpose of the deferred object is to expose the associated Promise instance as well as APIs
|
63 |
| - * that can be used for signaling the successful or unsuccessful completion of the task. |
| 67 | + * that can be used for signaling the successful or unsuccessful completion, as well as the status |
| 68 | + * of the task. |
64 | 69 | *
|
65 | 70 | * **Methods**
|
66 | 71 | *
|
67 | 72 | * - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection
|
68 | 73 | * constructed via `$q.reject`, the promise will be rejected instead.
|
69 | 74 | * - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
|
70 | 75 | * resolving it with a rejection constructed via `$q.reject`.
|
| 76 | + * - `notify(value)` - provides updates on the status of the promises execution. This may be called |
| 77 | + * multiple times before the promise is either resolved or rejected. |
71 | 78 | *
|
72 | 79 | * **Properties**
|
73 | 80 | *
|
|
84 | 91 | *
|
85 | 92 | * **Methods**
|
86 | 93 | *
|
87 |
| - * - `then(successCallback, errorCallback)` – regardless of when the promise was or will be resolved |
88 |
| - * or rejected, `then` calls one of the success or error callbacks asynchronously as soon as the result |
89 |
| - * is available. The callbacks are called with a single argument: the result or rejection reason. |
| 94 | + * - `then(successCallback, errorCallback, notifyCallback)` – regardless of when the promise was or |
| 95 | + * will be resolved or rejected, `then` calls one of the success or error callbacks asynchronously |
| 96 | + * as soon as the result is available. The callbacks are called with a single argument: the result |
| 97 | + * or rejection reason. Additionally, the notify callback may be called zero or more times to |
| 98 | + * provide a progress indication, before the promise is resolved or rejected. |
90 | 99 | *
|
91 | 100 | * This method *returns a new promise* which is resolved or rejected via the return value of the
|
92 |
| - * `successCallback` or `errorCallback`. |
| 101 | + * `successCallback`, `errorCallback`. It also notifies via the return value of the `notifyCallback` |
| 102 | + * method. The promise can not be resolved or rejected from the notifyCallback method. |
93 | 103 | *
|
94 | 104 | * - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
|
95 | 105 | *
|
|
0 commit comments