Class: ReusablePromiseMap

ReusablePromiseMap(configuration)

A map where each entry represents a keyed promise that can be reused. While the underlying map capacity is reached, every new call will be put in the queue that will be processed every time one of the promises is fulfilled.

Constructor

new ReusablePromiseMap(configuration)

Parameters:
Name Type Description
configuration object
Properties
Name Type Attributes Default Description
save boolean <optional>
false if set to `true`, stores the result of the first successful promise for each key.
capacity number <optional>
<nullable>
max capacity of the underlying container.
queueCapacity number <optional>
<nullable>
max capacity of the queue.
Source:

Classes

ReusablePromiseMap

Methods

(async) callByKey(key, createPromise) → {Promise.<T>}

Checks if a promise with the supplied key exists, if so, `await`s it, otherwise sets a new `Promise` produced by calling `createPromise` function. In case capacity is reached, the current call will be paused until the next promise(s) is resolved.
Parameters:
Name Type Description
key *
createPromise function
Source:
Returns:
Type
Promise.<T>

clear()

Clears the underlying `Promise` map and `reject`s all queued items.
Source:

reachedCapacity() → {boolean}

Returns `true` if capacity is reached.
Source:
Returns:
Type
boolean

shiftQueuedItems(limit, fopt)

Shifts up to `limit` items from the queue applying the supplied function to each.
Parameters:
Name Type Attributes Default Description
limit number
f function <optional>
({ resolve, reject: _ }) => resolve()
Source: