store/promiseUtil

Namespace

store/promiseUtil

Description:
  • This module contains utility methods for promises.

Source:

Methods

(static) delay(millisecs) → {Promise.<any>}

Description:
  • Use setTimeout with promise. This is useful when you want to do things like Promise.all( promise1, promiseUtil.delay(1000), ]);

Source:
Parameters:
Name Type Description
millisecs
Returns:
Type
Promise.<any>

(static) forEach(items, func) → {Promise}

Description:
  • Asynchronous forEach relying on promises that works in serial rather than parallell. It invokes a function on each item only after the promise from the previous item in the array has succeeded. If one of the promises fails the forEach promise fails altogheter. The result is provided in an array if the items is an array. In the case where the items is an object the same object is returned but with the values replaced with the result of the promise. (The function is applied to the value of each key in the items object.)

Source:
Parameters:
Name Type Description
items array | object
func function

a function that is applied to each item and must return a promise

Returns:
Type
Promise

(static) toPromise(value) → {Promise}

Description:
  • Makes sure a value is a promise, if needed wraps it as a promise. If the value the false boolean it is interpreted as a reject.

Source:
Parameters:
Name Type Description
value any | Promise

the value to wrap in a promise, if it already is a promise it is returned.

Returns:
Type
Promise