Skip to content

Commit e499433

Browse files
James Kleehjeffbcross
James Kleeh
authored andcommitted
docs($q): implement the same example for constructor as deferred
The current documentation has a `return` in the middle of nowhere and somewhat complicates the example with unnecessary code. This implements the same code as in the example for the other way of using $q in order to simplify the differences between them.
1 parent bb390ef commit e499433

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/ng/q.js

+21-18
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@
2323
* It can be used like so:
2424
*
2525
* ```js
26-
* return $q(function(resolve, reject) {
27-
* // perform some asynchronous operation, resolve or reject the promise when appropriate.
28-
* setInterval(function() {
29-
* if (pollStatus > 0) {
30-
* resolve(polledValue);
31-
* } else if (pollStatus < 0) {
32-
* reject(polledValue);
33-
* } else {
34-
* pollStatus = pollAgain(function(value) {
35-
* polledValue = value;
36-
* });
37-
* }
38-
* }, 10000);
39-
* }).
40-
* then(function(value) {
41-
* // handle success
26+
* // for the purpose of this example let's assume that variables `$q` and `okToGreet`
27+
* // are available in the current lexical scope (they could have been injected or passed in).
28+
*
29+
* function asyncGreet(name) {
30+
* // perform some asynchronous operation, resolve or reject the promise when appropriate.
31+
* return $q(function(resolve, reject) {
32+
* setTimeout(function() {
33+
* if (okToGreet(name)) {
34+
* resolve('Hello, ' + name + '!');
35+
* } else {
36+
* reject('Greeting ' + name + ' is not allowed.');
37+
* }
38+
* }, 1000);
39+
* });
40+
* }
41+
*
42+
* var promise = asyncGreet('Robin Hood');
43+
* promise.then(function(greeting) {
44+
* alert('Success: ' + greeting);
4245
* }, function(reason) {
43-
* // handle failure
46+
* alert('Failed: ' + reason);
4447
* });
4548
* ```
4649
*
@@ -56,7 +59,7 @@
5659
* asynchronous programming what `try`, `catch` and `throw` keywords are to synchronous programming.
5760
*
5861
* ```js
59-
* // for the purpose of this example let's assume that variables `$q`, `scope` and `okToGreet`
62+
* // for the purpose of this example let's assume that variables `$q` and `okToGreet`
6063
* // are available in the current lexical scope (they could have been injected or passed in).
6164
*
6265
* function asyncGreet(name) {

0 commit comments

Comments
 (0)