Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit c65fcc0

Browse files
colinfreivojtajina
authored andcommitted
docs($q): document notify behavior
Closes #3341
1 parent d9dbc6a commit c65fcc0

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/ng/q.js

+15-5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
* // since this fn executes async in a future turn of the event loop, we need to wrap
2727
* // our code into an $apply call so that the model changes are properly observed.
2828
* scope.$apply(function() {
29+
* deferred.notify('About to greet ' + name + '.');
30+
*
2931
* if (okToGreet(name)) {
3032
* deferred.resolve('Hello, ' + name + '!');
3133
* } else {
@@ -42,6 +44,8 @@
4244
* alert('Success: ' + greeting);
4345
* }, function(reason) {
4446
* alert('Failed: ' + reason);
47+
* }, function(update) {
48+
* alert('Got notification: ' + update);
4549
* });
4650
* </pre>
4751
*
@@ -60,14 +64,17 @@
6064
* A new instance of deferred is constructed by calling `$q.defer()`.
6165
*
6266
* 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.
6469
*
6570
* **Methods**
6671
*
6772
* - `resolve(value)` – resolves the derived promise with the `value`. If the value is a rejection
6873
* constructed via `$q.reject`, the promise will be rejected instead.
6974
* - `reject(reason)` – rejects the derived promise with the `reason`. This is equivalent to
7075
* 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.
7178
*
7279
* **Properties**
7380
*
@@ -84,12 +91,15 @@
8491
*
8592
* **Methods**
8693
*
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.
9099
*
91100
* 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.
93103
*
94104
* - `catch(errorCallback)` – shorthand for `promise.then(null, errorCallback)`
95105
*

0 commit comments

Comments
 (0)