store/RateLimit

Methods

addListener(listener)

Description:
  • Listener that will be notified if rate limitation is turned on (true is sent) or off (false is sent).

Source:
Parameters:
Name Type Description
listener function

clear()

Description:
  • Clear the queue of requests.

Source:

enqueue(fn, contextopt, argsopt) → {Promise}

Description:
  • Enqueue a request in the form of an asynchronous function, i.e. it has to return a promise.

Source:
Parameters:
Name Type Attributes Description
fn function

the function to add to the queue

context object <optional>

a context object that will become the "this" of the function, optional.

args array <optional>

an array of arguments, optional.

Returns:

a new potentially delayed promise with the same resolve and reject values.

Type
Promise

history() → {Array.<Object>}

Description:
  • The history is an array of buckets where requests have been made, each past bucket is documented in the history with an object with attributes:

    • amount - amount of requests made in the bucket.
    • time - time the bucket started.
    • limitAt - time when the bucket switched over from burst to rate limitation mode, may not exist.
Source:
Returns:
Type
Array.<Object>

queueLength() → {number}

Source:
Returns:

the amount of enqueued requests.

Type
number

removeListener(listener)

Description:
  • Remove the provided rate limitation listener.

Source:
Parameters:
Name Type Description
listener function

wait() → {Promise}

Description:
  • The promise will resolve in a time frame between 0 milliseconds and the maximum wait time calculated by dividing the time period with the request limit in naive mode. In burst mode the wait time is half that. The actual time we wait depends on how long time ago the last request was made.

    This is a utility function that can be used by applications that wants to behave nice and wait before enqueueing a lot of functions.

Source:
Returns:

The promise will be resolved when it is time to do the next request.

Type
Promise

waitTime() → {number}

Description:
  • The time to wait before next request will be sent. The time will be a number in milliseconds between 0 and the maximum wait time. In naive mode the wait time is the quotient between time period and the request limit. In burst mode the wait time is half of the naive mode. The actual time we wait depends on how long time ago the last request was made.

Source:
Returns:

The time in milliseconds before next request can be sent.

Type
number