Class: FidelityPromise

FidelityPromise

Represents the eventual result of an asynchronous operation.

new FidelityPromise(fn)

Creates a new FidelityPromise.
Parameters:
Name Type Description
fn function The executor function. It is executed immediately, and should accept two resolver functions, 'resolve' and 'reject'. Calling them either fulfills or rejects the promise, respectively. Typically, the executor function will initiate some asynchronous task, and the call 'resolve' with the result, or 'reject' if there was an error.

Members


state

Returns the current state of this promise. Possible values are `Fidelity.PENDING`, `Fidelity.FULFILLED`, or `Fidelity.REJECTED`.

value

Gets the current value of this promise. May be undefined.

Methods


<static> all(promises)

Returns the results of all resolved promises, or the cause of the first failed promise.
Parameters:
Name Type Description
promises iterable an iterable
Returns:
an Array of results, or the cause of the first rejected promise
Type
any

<static> deferred()

Creates a `deferred` object, containing a promise which may be resolved or rejected at some point in the future.
Returns:
  • deferred The deferred object
    Type
    object
  • deferred.resolve(value) The resolve function
    Type
    function
  • deferred.reject(cause) The reject function
    Type
    function
  • deferred.promise The inner promise object
    Type
    object

<static> promise(fn)

Creates a promise that will be resolved or rejected at some time in the future.
Parameters:
Name Type Description
fn function The function that will do the work of this promise. The function is passed two function arguments, `resolve()` and `reject()`. Call one of these when the work has completed (or failed).
Deprecated:
  • Use new FidelityPromise()
Returns:
A promise object
Type
FidelityPromise

<static> race(promises)

Returns a promise that resolves or rejects as soon as one of the promises in the supplied iterable resolves or rejects with the value or reason from that promise.
Parameters:
Name Type Description
promises iterable an iterable
Returns:
the first value or cause that was resolved or rejected by one of the supplied promises.
Type
any

<static> reject(reason)

Returns a promise that has been rejected.
Parameters:
Name Type Description
reason any The reason the promise was rejected
Returns:
a rejected promise
Type
FidelityPromise

<static> resolve(value)

Returns a promise that is resolved with `value`.
Parameters:
Name Type Description
value any The value to resolve the returned promise with
Returns:
A promise resolved with `value`
Type
FidelityPromise

catch(onRejected)

Syntactic sugar for `this.then(null, onRejected)`.
Parameters:
Name Type Description
onRejected function the function to invoke when this promise is rejected.
Returns:
Type
FidelityPromise

then(onFulfilled, onRejected)

Follows the [Promises/A+](https://promisesaplus.com/) spec for a `then` function.
Parameters:
Name Type Description
onFulfilled function the function to invoke when this promise has been resolved.
onRejected function the function to invoke when this promise has been rejected.
Returns:
Type
FidelityPromise