1 | define([ |
---|
2 | "../_base/lang" |
---|
3 | ], function(lang){ |
---|
4 | "use strict"; |
---|
5 | |
---|
6 | // module: |
---|
7 | // dojo/promise/Promise |
---|
8 | |
---|
9 | function throwAbstract(){ |
---|
10 | throw new TypeError("abstract"); |
---|
11 | } |
---|
12 | |
---|
13 | return lang.extend(function Promise(){ |
---|
14 | // summary: |
---|
15 | // The public interface to a deferred. |
---|
16 | // description: |
---|
17 | // The public interface to a deferred. All promises in Dojo are |
---|
18 | // instances of this class. |
---|
19 | }, { |
---|
20 | then: function(callback, errback, progback){ |
---|
21 | // summary: |
---|
22 | // Add new callbacks to the promise. |
---|
23 | // description: |
---|
24 | // Add new callbacks to the deferred. Callbacks can be added |
---|
25 | // before or after the deferred is fulfilled. |
---|
26 | // callback: Function? |
---|
27 | // Callback to be invoked when the promise is resolved. |
---|
28 | // Receives the resolution value. |
---|
29 | // errback: Function? |
---|
30 | // Callback to be invoked when the promise is rejected. |
---|
31 | // Receives the rejection error. |
---|
32 | // progback: Function? |
---|
33 | // Callback to be invoked when the promise emits a progress |
---|
34 | // update. Receives the progress update. |
---|
35 | // returns: dojo/promise/Promise |
---|
36 | // Returns a new promise for the result of the callback(s). |
---|
37 | // This can be used for chaining many asynchronous operations. |
---|
38 | |
---|
39 | throwAbstract(); |
---|
40 | }, |
---|
41 | |
---|
42 | cancel: function(reason, strict){ |
---|
43 | // summary: |
---|
44 | // Inform the deferred it may cancel its asynchronous operation. |
---|
45 | // description: |
---|
46 | // Inform the deferred it may cancel its asynchronous operation. |
---|
47 | // The deferred's (optional) canceler is invoked and the |
---|
48 | // deferred will be left in a rejected state. Can affect other |
---|
49 | // promises that originate with the same deferred. |
---|
50 | // reason: any |
---|
51 | // A message that may be sent to the deferred's canceler, |
---|
52 | // explaining why it's being canceled. |
---|
53 | // strict: Boolean? |
---|
54 | // If strict, will throw an error if the deferred has already |
---|
55 | // been fulfilled and consequently cannot be canceled. |
---|
56 | // returns: any |
---|
57 | // Returns the rejection reason if the deferred was canceled |
---|
58 | // normally. |
---|
59 | |
---|
60 | throwAbstract(); |
---|
61 | }, |
---|
62 | |
---|
63 | isResolved: function(){ |
---|
64 | // summary: |
---|
65 | // Checks whether the promise has been resolved. |
---|
66 | // returns: Boolean |
---|
67 | |
---|
68 | throwAbstract(); |
---|
69 | }, |
---|
70 | |
---|
71 | isRejected: function(){ |
---|
72 | // summary: |
---|
73 | // Checks whether the promise has been rejected. |
---|
74 | // returns: Boolean |
---|
75 | |
---|
76 | throwAbstract(); |
---|
77 | }, |
---|
78 | |
---|
79 | isFulfilled: function(){ |
---|
80 | // summary: |
---|
81 | // Checks whether the promise has been resolved or rejected. |
---|
82 | // returns: Boolean |
---|
83 | |
---|
84 | throwAbstract(); |
---|
85 | }, |
---|
86 | |
---|
87 | isCanceled: function(){ |
---|
88 | // summary: |
---|
89 | // Checks whether the promise has been canceled. |
---|
90 | // returns: Boolean |
---|
91 | |
---|
92 | throwAbstract(); |
---|
93 | }, |
---|
94 | |
---|
95 | always: function(callbackOrErrback){ |
---|
96 | // summary: |
---|
97 | // Add a callback to be invoked when the promise is resolved |
---|
98 | // or rejected. |
---|
99 | // callbackOrErrback: Function? |
---|
100 | // A function that is used both as a callback and errback. |
---|
101 | // returns: dojo/promise/Promise |
---|
102 | // Returns a new promise for the result of the callback/errback. |
---|
103 | |
---|
104 | return this.then(callbackOrErrback, callbackOrErrback); |
---|
105 | }, |
---|
106 | |
---|
107 | otherwise: function(errback){ |
---|
108 | // summary: |
---|
109 | // Add new errbacks to the promise. |
---|
110 | // errback: Function? |
---|
111 | // Callback to be invoked when the promise is rejected. |
---|
112 | // returns: dojo/promise/Promise |
---|
113 | // Returns a new promise for the result of the errback. |
---|
114 | |
---|
115 | return this.then(null, errback); |
---|
116 | }, |
---|
117 | |
---|
118 | trace: function(){ |
---|
119 | return this; |
---|
120 | }, |
---|
121 | |
---|
122 | traceRejected: function(){ |
---|
123 | return this; |
---|
124 | }, |
---|
125 | |
---|
126 | toString: function(){ |
---|
127 | // returns: string |
---|
128 | // Returns `[object Promise]`. |
---|
129 | |
---|
130 | return "[object Promise]"; |
---|
131 | } |
---|
132 | }); |
---|
133 | }); |
---|