Throttler
Class: Throttler
Promise Throttler
Allow you to queue promise and execute them concurrently
Several libraries does that
The queue method still gives you a simple Promise linked to the resolution of your queued item, so you can still wait for the execution of the specific item
Constructors
new Throttler(concurrency)
new Throttler(
concurrency):Throttler
Parameters
• concurrency: number= 10
max concurrent promise to execute
Returns
Source
packages/core/src/utils/throttler.ts:48
Properties
_queue
protected_queue:ThrottlerItem[] =[]
Current queue
Source
packages/core/src/utils/throttler.ts:34
_waiters
protected_waiters: () =>void[] =[]
Resolver for each call to waitForCompletion
Source
packages/core/src/utils/throttler.ts:42
concurrency
protectedconcurrency:number=10
max concurrent promise to execute
Source
packages/core/src/utils/throttler.ts:48
current
current:
number=0
Number of promises in-progress
Source
packages/core/src/utils/throttler.ts:38
Methods
add()
protectedadd():void
Internal manage the promise concurrency
Returns
void
Source
packages/core/src/utils/throttler.ts:152
execute()
execute(
method,name):Promise<any>
Execute a new promise
Alias for queue
Parameters
• method: () => Promise<any> | () => Promise<any>[]
• name: string= undefined
Returns
Promise<any>
Source
packages/core/src/utils/throttler.ts:70
getInProgress()
getInProgress():
ThrottlerItem[]
Get inprogress items
Returns
ThrottlerItem[]
Source
packages/core/src/utils/throttler.ts:114
getSize()
getSize():
number
Get global queue size
Returns
number
Source
packages/core/src/utils/throttler.ts:122
queue()
queue(
method,name):Promise<any>
Queue a new promise
Parameters
• method: () => Promise<any> | () => Promise<any>[]
executor that return the promise to queue
• name: string= undefined
of the task, usefull when calling getInProgress
Returns
Promise<any>
Source
packages/core/src/utils/throttler.ts:84
setConcurrency()
setConcurrency(
concurrency):void
Set the concurrency
Parameters
• concurrency: number
newValue
If decreased, it will be in effect only when current promises resolve If increased, it will have immediate effect
Returns
void
Source
packages/core/src/utils/throttler.ts:100
wait()
wait():
Promise<void>
Wait until every promise resolve
Returns
Promise<void>
Source
packages/core/src/utils/throttler.ts:139
waitForCompletion()
waitForCompletion():
Promise<void>
Returns
Promise<void>
Deprecated
Source
packages/core/src/utils/throttler.ts:130
run()
staticrun(method,concurrency):Promise<void>
Run a Throttler without having to instanciate it
Parameters
• method: () => Promise<any> | () => Promise<any>[]
• concurrency: number= 10
Returns
Promise<void>