Skip to main content

Class: RateLimitManager<K>

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:3

Extends

Type Parameters

Type ParameterDefault type
Kstring

Constructors

new RateLimitManager()

new RateLimitManager<K>(time: number, limit: number): RateLimitManager<K>

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:23

Parameters

ParameterTypeDefault valueDescription
timenumberundefinedThe amount of milliseconds for the ratelimits from this manager to expire.
limitnumber1The amount of times a RateLimit can drip before it's limited.

Returns

RateLimitManager<K>

Overrides

Map<K, RateLimit<K>>.constructor

Properties

[toStringTag]

readonly [toStringTag]: string

Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:137

Inherited from

Map.[toStringTag]


limit

readonly limit: number

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:12

The amount of times a RateLimit can drip before it's limited.


size

readonly size: number

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:45

Returns

the number of elements in the Map.

Inherited from

Map.size


sweepInterval

private sweepInterval: undefined | null | Timeout

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:17

The interval to sweep expired ratelimits.


time

readonly time: number

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:7

The amount of milliseconds for the ratelimits from this manager to expire.


[species]

readonly static [species]: MapConstructor

Defined in: node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts:319

Inherited from

Map.[species]


sweepIntervalDuration

static sweepIntervalDuration: number = 30_000

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:75

The delay in milliseconds for RateLimitManager.sweepInterval.

Methods

[iterator]()

[iterator](): IterableIterator<[K, RateLimit<K>]>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:119

Returns an iterable of entries in the map.

Returns

IterableIterator<[K, RateLimit<K>]>

Inherited from

Map.[iterator]


acquire()

acquire(id: K): RateLimit<K>

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:34

Gets a RateLimit from this manager or creates it if it does not exist.

Parameters

ParameterTypeDescription
idKThe id for the RateLimit

Returns

RateLimit<K>


clear()

clear(): void

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:20

Returns

void

Inherited from

Map.clear


create()

create(id: K): RateLimit<K>

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:42

Creates a RateLimit for this manager.

Parameters

ParameterTypeDescription
idKThe id the RateLimit belongs to

Returns

RateLimit<K>


delete()

delete(key: K): boolean

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:24

Parameters

ParameterType
keyK

Returns

boolean

true if an element in the Map existed and has been removed, or false if the element does not exist.

Inherited from

Map.delete


entries()

entries(): IterableIterator<[K, RateLimit<K>]>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:124

Returns an iterable of key, value pairs for every entry in the map.

Returns

IterableIterator<[K, RateLimit<K>]>

Inherited from

Map.entries


forEach()

forEach(callbackfn: (value: RateLimit<K>, key: K, map: Map<K, RateLimit<K>>) => void, thisArg?: any): void

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:28

Executes a provided function once per each key/value pair in the Map, in insertion order.

Parameters

ParameterType
callbackfn(value: RateLimit<K>, key: K, map: Map<K, RateLimit<K>>) => void
thisArg?any

Returns

void

Inherited from

Map.forEach


get()

get(key: K): undefined | RateLimit<K>

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:33

Returns a specified element from the Map object. If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

Parameters

ParameterType
keyK

Returns

undefined | RateLimit<K>

Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

Inherited from

Map.get


has()

has(key: K): boolean

Defined in: node_modules/typescript/lib/lib.es2015.collection.d.ts:37

Parameters

ParameterType
keyK

Returns

boolean

boolean indicating whether an element with the specified key exists or not.

Inherited from

Map.has


keys()

keys(): IterableIterator<K>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:129

Returns an iterable of keys in the map

Returns

IterableIterator<K>

Inherited from

Map.keys


set()

set(id: K, value: RateLimit<K>): this

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:53

Wraps Collection's set method to set interval to sweep inactive RateLimits.

Parameters

ParameterTypeDescription
idKThe id the RateLimit belongs to
valueRateLimit<K>The RateLimit to set

Returns

this

Overrides

Map.set


sweep()

sweep(): void

Defined in: projects/utilities/packages/ratelimits/src/lib/RateLimitManager.ts:61

Wraps Collection's sweep method to clear the interval when this manager is empty.

Returns

void


values()

values(): IterableIterator<RateLimit<K>>

Defined in: node_modules/typescript/lib/lib.es2015.iterable.d.ts:134

Returns an iterable of values in the map

Returns

IterableIterator<RateLimit<K>>

Inherited from

Map.values


groupBy()

static groupBy<K, T>(items: Iterable<T>, keySelector: (item: T, index: number) => K): Map<K, T[]>

Defined in: node_modules/typescript/lib/lib.esnext.collection.d.ts:25

Groups members of an iterable according to the return value of the passed callback.

Type Parameters

Type Parameter
K
T

Parameters

ParameterTypeDescription
itemsIterable<T>An iterable.
keySelector(item: T, index: number) => KA callback which will be invoked for each item in items.

Returns

Map<K, T[]>

Inherited from

Map.groupBy