@toolcog/util/task
Toolcog utilities
Classes
Dispatcher<EventTypes>
Extends
Emitter
<EventTypes
>
Type Parameters
• EventTypes extends DispatcherEvents
= DispatcherEvents
Constructors
new Dispatcher()
new Dispatcher<
EventTypes
>(options
?):Dispatcher
<EventTypes
>
Parameters
• options?: DispatcherOptions
Returns
Dispatcher
<EventTypes
>
Overrides
Defined in
Properties
error
readonly
static
error: typeoferror
Inherited from
Defined in
errorMonitor
readonly
static
errorMonitor: typeoferrorMonitor
Inherited from
Defined in
Accessors
concurrency
get
concurrency():number
Returns
number
Defined in
paused
get
paused():boolean
Returns
boolean
Defined in
pending
get
pending():number
Returns
number
Defined in
size
get
size():number
Returns
number
Defined in
Methods
addListener()
addListener<
Event
>(event
,listener
,options
?):this
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
• listener: EmitListener
<EventTypes
[Event
]>
• options?: EmitListenerOptions
Returns
this
Inherited from
Defined in
emit()
emit<
Event
>(event
, …args
):boolean
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
• …args: EventTypes
[Event
]
Returns
boolean
Inherited from
Defined in
enqueue()
enqueue<
T
>(task
,options
?):Promise
<T
>
Type Parameters
• T
Parameters
• task: Task
<T
>
• options?: DispatchOptions
Returns
Promise
<T
>
Defined in
enqueueAll()
enqueueAll<
T
>(tasks
,options
):Promise
<T
[]>
Type Parameters
• T
Parameters
• tasks: readonly Task
<T
>[]
• options: DispatchOptions
= {}
Returns
Promise
<T
[]>
Defined in
events()
events():
IterableIterator
<keyofEventTypes
,any
,any
>
Returns
IterableIterator
<keyof EventTypes
, any
, any
>
Inherited from
Defined in
isEmpty()
isEmpty():
boolean
Returns
boolean
Defined in
isIdle()
isIdle():
boolean
Returns
boolean
Defined in
listeners()
listeners<
Event
>(event
):IterableIterator
<EmitListener
<EventTypes
[Event
]>,any
,any
>
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
Returns
IterableIterator
<EmitListener
<EventTypes
[Event
]>, any
, any
>
Inherited from
Defined in
on()
on<
Event
>(event
,options
?):AsyncIterableIterator
<EventTypes
[Event
],any
,any
>
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
• options?: EmitAsyncOptions
Returns
AsyncIterableIterator
<EventTypes
[Event
], any
, any
>
Inherited from
Defined in
onAvailable()
onAvailable(
backlog
):Promise
<void
>
Parameters
• backlog: number
Returns
Promise
<void
>
Defined in
once()
once<
Event
>(event
,options
?):Promise
<EventTypes
[Event
]>
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
• options?: EmitAsyncOptions
Returns
Promise
<EventTypes
[Event
]>
Inherited from
Defined in
onEmpty()
onEmpty():
Promise
<void
>
Returns
Promise
<void
>
Defined in
onIdle()
onIdle():
Promise
<void
>
Returns
Promise
<void
>
Defined in
pause()
pause():
void
Returns
void
Defined in
removeListener()
removeListener<
Event
>(event
,listener
,options
?):this
Type Parameters
• Event extends string
| number
| symbol
Parameters
• event: Event
• listener: EmitListener
<EventTypes
[Event
]>
• options?: EmitListenerOptions
Returns
this
Inherited from
Defined in
resume()
resume():
void
Returns
void
Defined in
Interfaces
DispatcherOptions
Extends
Properties
captureRejections?
optional
captureRejections:boolean
Inherited from
EmitterOptions
.captureRejections
Defined in
concurrency?
optional
concurrency:number
The maximum number of tasks that can be concurrently executing at any given time. Used to limit the concurrency of task execution.
Default
Infinity
Defined in
paused?
optional
paused:boolean
Whether to initialize the dispatcher in the paused state. Used to defer executing tasks until Dispatcher.resume is called.
Default
false
Defined in
pendingCarryover?
optional
pendingCarryover:boolean
Whether to count pending tasks towards the rateLimit
when entering
a new rate limit interval. Used to ensure that tasks started during
a previous interval are counted towards the rate limit of the next
interval if they haven’t finished executing yet.
Default
false
Defined in
Queue()?
optional
Queue: <T
>() =>Queue
<T
>
The function used to create the dispatcher’s run queue.
Returns
Queue
<T
>
Default
Defined in
rateInterval?
optional
rateInterval:number
The number of milliseconds in each rate limit interval. If zero or infinite, then task execution will not be rate limited.
Default
0
Defined in
rateLimit?
optional
rateLimit:number
The maximum number of tasks that can be executed in any given
rateInterval
. Used to rate limit task execution. If rateLimit
is infinite, or if rateInterval
is zero or infinite, then task
execution will not be rate limited.
Default
Infinity
Defined in
retry?
optional
retry:number
|boolean
|RetryOptions
Defined in
DispatchOptions
Properties
priority?
optional
priority:number
The execution priority of the task. Lower numeric values correspond to higher priority tasks.
Default
0
Defined in
retry?
optional
retry:number
|boolean
|RetryOptions
Defined in
signal?
optional
signal:null
|AbortSignal
The signal used to cancel execution of the task.
Defined in
RetryOptions
Properties
factor?
optional
factor:number
Defined in
jitter?
optional
jitter:boolean
Defined in
maxTimeout?
optional
maxTimeout:number
Defined in
minTimeout?
optional
minTimeout:number
Defined in
onFailedAttempt()?
optional
onFailedAttempt: (reason
) =>void
Parameters
• reason: unknown
Returns
void
Defined in
retries?
optional
retries:number
Defined in
shouldRetry()?
optional
shouldRetry: (reason
) =>boolean
Parameters
• reason: unknown
Returns
boolean
Defined in
signal?
optional
signal:null
|AbortSignal
Defined in
TaskOptions
Properties
attempt?
optional
attempt:number
The number of times the task has been retried.
Defined in
signal?
optional
signal:null
|AbortSignal
A signal to cancel the execution of the task.
Defined in
Type Aliases
DispatcherEvents
DispatcherEvents:
object
Type declaration
[error]
[error]: [
unknown
]
complete
complete: []
empty
empty: []
enqueue
enqueue: []
execute
execute: []
finish
finish: []
idle
idle: []
pause
pause: []
resume
resume: []
Defined in
Task()<T>
Task<
T
>: (options
) =>T
|PromiseLike
<T
>
Type Parameters
• T = unknown
Parameters
• options: TaskOptions
Returns
T
| PromiseLike
<T
>
Defined in
Functions
retry()
retry<
T
>(task
,options
?):Promise
<T
>
Type Parameters
• T
Parameters
• task: Task
<T
>
• options?: RetryOptions
Returns
Promise
<T
>