Constructor
new Async(promise, onCancelledopt)
Creates a new cancellable promise. The cancellation callback must be a no-op if the action is already performed.
- Parameters:
-
Name Type Attributes Description promise
{Promise|Deferred|function|Error|Object} the promise to wrap onCancelled
{function} <optional>
the cancellation callback function - Source:
- RapidContext_Async.js, line 41
Methods
addBoth(callbackopt) → {Async}
Registers a callback function to this promise.
- Parameters:
-
Name Type Attributes Description callback
{function} <optional>
a callback if promise either fulfilled or rejected - Returns:
- {Async} this same promise
- Deprecated:
- Provided for `MochiKit.Async.Deferred` compatibility
- Source:
- RapidContext_Async.js, line 196
addCallback(callbackopt) → {Async}
Registers a fulfilled callback function to this promise.
- Parameters:
-
Name Type Attributes Description callback
{function} <optional>
a callback if promise fulfilled - Returns:
- {Async} this same promise
- Deprecated:
- Provided for `MochiKit.Async.Deferred` compatibility
- Source:
- RapidContext_Async.js, line 159
addCallbacks(onFulfilledopt, onRejectedopt) → {Async}
Registers one or two callback functions to this promise.
- Parameters:
-
Name Type Attributes Description onFulfilled
{function} <optional>
a callback if promise fulfilled onRejected
{function} <optional>
a callback if promise rejected - Returns:
- {Async} this same promise
- Deprecated:
- Provided for `MochiKit.Async.Deferred` compatibility
- Source:
- RapidContext_Async.js, line 146
addErrback(errback) → {Async}
Registers a reject callback function to this promise.
- Parameters:
-
Name Type Description errback
{function} a callback if promise rejected - Returns:
- {Async} this same promise
- Deprecated:
- Provided for `MochiKit.Async.Deferred` compatibility
- Source:
- RapidContext_Async.js, line 177
cancel()
Cancels this promise and calls the registered cancellation handler. No other callbacks will be triggered after the promise has been cancelled (except finalizer).
- Source:
- RapidContext_Async.js, line 131
catch(onRejected) → {Async}
Registers a reject callback function to this promise.
- Parameters:
-
Name Type Description onRejected
{function} a callback if promise rejected - Returns:
- {Async} a new promise that resolves to whatever value the callback function returned
- Source:
- RapidContext_Async.js, line 107
finally(onFinally) → {Async}
Registers a finalizer callback function to this promise. Note that the finalizer MAY NOT BE CALLED if the promise is cancelled.
- Parameters:
-
Name Type Description onFinally
{function} a callback for promise resolved - Returns:
- {Async} a new promise
- Source:
- RapidContext_Async.js, line 119
then(onFulfilledopt, onRejectedopt) → {Async}
Registers one or two callback functions to this promise.
- Parameters:
-
Name Type Attributes Description onFulfilled
{function} <optional>
a callback if promise fulfilled onRejected
{function} <optional>
a callback if promise rejected - Returns:
- {Async} a new promise that resolves to whatever value the callback functions return
- Source:
- RapidContext_Async.js, line 94
(static) css(url) → {Async}
Injects a CSS stylesheet to the current page.
- Parameters:
-
Name Type Description url
{string} the stylesheet URL to load - Returns:
-
{Async}
a promise that resolves with the DOM
<link>
element - Source:
- RapidContext_Async.js, line 254
(static) img(url) → {Async}
Loads an image from a URL.
- Parameters:
-
Name Type Description url
{string} the image URL to load - Returns:
-
{Async}
a promise that resolves with the DOM
<img>
element - Source:
- RapidContext_Async.js, line 243
(static) isPromise(value) → {boolean}
Checks if an object conforms to the Promise
API.
- Parameters:
-
Name Type Description value
{Object} the object to check - Returns:
-
{boolean}
true
if the object is a promise, orfalse
otherwise - Source:
- RapidContext_Async.js, line 29
(static) script(url) → {Async}
Injects a JavaScript to the current page.
- Parameters:
-
Name Type Description url
{string} the script URL to load - Returns:
-
{Async}
a promise that resolves with the DOM
<script>
element - Source:
- RapidContext_Async.js, line 266
(static) wait(millis, valueopt) → {Async}
Returns a delayed value.
- Parameters:
-
Name Type Attributes Description millis
{number} the number of milliseconds to wait value
{Object} <optional>
the value to resolve with - Returns:
- {Async} a new promise that resolves with the value
- Source:
- RapidContext_Async.js, line 228
(static) xhr(url, optionsopt) → {Async}
Performs an XmlHttpRequest to a URL.
- Parameters:
-
Name Type Attributes Description url
{string} the URL to request options
{Object} <optional>
the request options - Returns:
- {Async} a new promise that resolves with either the XHR object, or an error if the request failed
- Source:
- RapidContext_Async.js, line 303