Deferred 编辑
A Deferred
object is returned by the PromiseUtils.defer()
method to provide a new promise along with methods to change its state.
Method overview
void resolve([optional] aValue); |
void reject([optional] aReason); |
Properties
Attribute | Type | Description |
promise Read only | Promise | A newly created promise, initially in the pending state. |
Methods
resolve()
Fulfills the associated promise with the specified value, or propagates the state of an existing promise. If the associated promise has already been resolved, either to a value, a rejection, or another promise, this method does nothing.
Note: This function is exactly same asPromise
constructor's resolve
argument, and can be called with any value of this
. Note: Calling this method with a pending promise as the aValue
argument, and then calling it again with another value before the promise is resolved or rejected, will have no effect the second time, as the associated promise is already resolved to the pending promise value as its resolution.void resolve( aValue );
Parameters
aValue
Optional- If this value is not a promise, including
undefined
, it becomes the fulfillment value of the associated promise. If this value is a promise, then the associated promise will be resolved to the passed promise, and follow the state as the provided promise (including any future transitions).
reject()
Rejects the associated promise with the specified reason. If the promise has already been resolved, either to a value, a rejection, or another promise, this method does nothing.
Note: This function is exactly same asPromise
constructor's reject
argument, and can be called with any value of this
.void reject( aReason );
Parameters
aReason
OptionalThe rejection reason for the associated promise. Although the reason can be
Note: This argument should not be a promise. Specifying a rejected promise would make the rejection reason equal to the rejected promise itself, and not its rejection reason.undefined
, it is generally anError
object, like in exception handling.
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论