Class: Token

core/token-pooling/token-pool~Token(id, data, usesRemaining, nextReset)

Encapsulate a rate-limited token, with a user-provided ID and user-provided data.

Each token has a notion of the number of uses remaining until exhausted, and the next reset time, when it can be used again even if it's exhausted.

Constructor

new Token(id, data, usesRemaining, nextReset)

Token Constructor

Parameters:
Name Type Description
id string

token string

data *

reserved for future use

usesRemaining number

Number of uses remaining until the token is exhausted

nextReset number

Time when the token can be used again even if it's exhausted (unix timestamp)

Source:

Methods

freeze()

Freeze the uses remaining and next reset values. Helpful for keeping stable ordering for a valid priority queue.

Source:

invalidate()

Indicate that the token should no longer be used.

Source:

unfreeze()

Unfreeze the uses remaining and next reset values.

Source:

update(usesRemaining, nextReset)

Update the uses remaining and next reset time for a token.

Parameters:
Name Type Description
usesRemaining number

Number of uses remaining until the token is exhausted

nextReset number

Time when the token can be used again even if it's exhausted (unix timestamp)

Source: