Module: rgjs/promise

RGJS6 Promise module.

Methods


<static> abortable(signal, promise)

Get an abortable promise. Based on https://jakearchibald.com/2020/events-and-gc/

Parameters:
Name Type Description
signal AbortController.signal
promise Promise
Returns:
Type
Promise

<static> promise()

Get a resolved promise.
Alias of resolve().

Deprecated:
  • Yes
See:
  • rgjs/obj/promise

<static> promisify(func, args)

Promisify a callback-based function.
Note #1: Supply __callback__ and __error__ to indicate position of the callback arguments passed to func.
Note #2: If the callback is called with multiple arguments, they are resolved as an array.

Parameters:
Name Type Argument Description
func function

The function.

args * <repeatable>

Arguments for the function.

Returns:
Type
Promise
Example
rgjs.promise.promisify(rgjs.ajax.dom.loadScript, 'js/script.js', '__callback__', '__error__', { ... });

<static> reject(reason)

Return a rejected promise.

Parameters:
Name Type Description
reason *

Optional. The reason the promise will reject.

Returns:

A rejected promise.

Type
Promise
Example
rgjs.promise.reject();

<static> resolve(resolved_value)

Get a resolved promise.

Parameters:
Name Type Description
resolved_value *

Optional. The value the promise will resolve.

Returns:
Type
Promise
Example
rgjs.promise.promise()
.then(() => { ... })

<static> retry(fn [, delay] [, maxretry])

Retry a function until it resolves or returns true (or maxretry is reached).
Based on https://stackoverflow.com/q/38213668/781094

Parameters:
Name Type Argument Default Description
fn function

A function that should return a promise (which resolves or rejects) or a boolean (true or false).

delay number <optional>
1000

The delay between retries in milliseconds. Defaults to 1000.

maxretry number <optional>
99

The maximum number of retries. Defaults to 99;

Returns:
Type
Promise
Examples
rgjs.promise.retry( rgjs.promise.promise );
rgjs.promise.retry( () => { return true; });

<static> wait(time, id)

Wait.

Parameters:
Name Type Description
time number

Time to wait in milliseconds. Defaults to 0.

id string

Optional. Can be used to cancel the wait using rgjs.schedule.clearTimeout(id). Note: This will not resolve or reject the promise!

Returns:
Type
Promise
Example
rgjs.promise.wait(500)
.then(() => { ... })