Documentation / @eventkit/base / QueueScheduler
Class: QueueScheduler
A scheduler that limits the number of actions that can execute concurrently.
The QueueScheduler
maintains a global queue of actions waiting to be executed and ensures that no more than a specified number of actions are executing at any given time. When an action completes, the next action in the queue is executed if there's room under the concurrency limit.
This scheduler is useful when you want to control the processing order of side effects, especially when they involve asynchronous operations that might otherwise complete out of order.
Extends
Implements
Constructors
Constructor
new QueueScheduler(init): QueueScheduler
Creates a new QueueScheduler.
Parameters
Parameter | Type | Description |
---|---|---|
init | QueueSchedulerInit | Configuration options for the scheduler. |
Returns
QueueScheduler
Overrides
Methods
add()
add(subject, promise): void
Adds a promise that is "owned" by a subject. This means that the promise will be observed by the scheduler and will be used to determine when the subject's work has completed.
This method also handles the special case of a subscriber, since subscribers are expected to be owned by an observable. If the subject is a subscriber, we also add the promise to it's observable.
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject that "owns" the promise. |
promise | PromiseLike <void > | The promise to be added to the subject. |
Returns
void
Implementation of
Inherited from
dispose()
dispose(subject): Promise<void>
Disposes of a subject by executing all cleanup actions and waiting for all promises to resolve.
This method executes all cleanup actions associated with the subject and waits for both regular promises and cleanup actions to complete before removing the subject from the scheduler. Unlike the promise()
method which waits for work to complete before disposing, this method immediately executes cleanup work and can be called independently.
When a subject is disposed:
- All cleanup actions are executed immediately
- The method waits for all promises and cleanup actions to resolve
- The subject is removed from the scheduler's tracking collections
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject to dispose of and remove from the scheduler |
Returns
Promise
<void
>
A promise that resolves when the subject has been fully disposed
Implementation of
Inherited from
promise()
promise(subject): Promise<void>
Returns a promise that will resolve when the subject's work has completed and all scheduled work has been executed (including cleanup work).
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject whose work is being awaited. |
Returns
Promise
<void
>
Implementation of
Inherited from
schedule()
schedule(subject, action): void
Schedules an action for execution. The action will be queued and executed when there's room under the concurrency limit.
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject that "owns" the action. |
action | ScheduledAction <any > | The action to be scheduled. |
Returns
void