Promise.Resolver Class
Represents an asynchronous operation. Provides a
standard API for subscribing to the moment that the operation completes either
successfully (fulfill()
) or unsuccessfully (reject()
).
Constructor
Promise.Resolver
-
promise
Parameters:
-
promise
PromiseThe promise instance this resolver will be handling
Item Index
Properties
Methods
_notify
-
subs
-
result
Executes an array of callbacks from a specified context, passing a set of arguments.
Parameters:
-
subs
Function[]The array of subscriber callbacks
-
result
AnyValue to pass the callbacks
_wrap
-
thenFulfill
-
thenReject
-
fn
Wraps the callback in Y.soon to guarantee its asynchronous execution. It
also catches exceptions to turn them into rejections and links promises
returned from the then
callback.
Parameters:
Returns:
fulfill
-
value
Resolves the promise, signaling successful completion of the
represented operation. All "onFulfilled" subscriptions are executed and passed
the value provided to this method. After calling fulfill()
, reject()
and
notify()
are disabled.
Parameters:
-
value
AnyValue to pass along to the "onFulfilled" subscribers
getStatus
()
String
Returns the current status of the Resolver as a string "pending", "fulfilled", or "rejected".
Returns:
reject
-
value
Resolves the promise, signaling unsuccessful completion of the
represented operation. All "onRejected" subscriptions are executed with
the value provided to this method. After calling reject()
, resolve()
and notify()
are disabled.
Parameters:
-
value
AnyValue to pass along to the "reject" subscribers
then
-
[callback]
-
[errback]
Schedule execution of a callback to either or both of "resolve" and
"reject" resolutions for the Resolver. The callbacks
are wrapped in a new Resolver and that Resolver's corresponding promise
is returned. This allows operation chaining ala
functionA().then(functionB).then(functionC)
where functionA
returns
a promise, and functionB
and functionC
may return promises.
Parameters:
Returns:
Properties
_status
String
private
The status of the operation. This property may take only one of the following values: 'pending', 'fulfilled' or 'rejected'.
Default: 'pending'