Documentation / @eventkit/base / SubjectQueueScheduler
Class: SubjectQueueScheduler
A scheduler that maintains separate queues for each subject with a concurrency limit applied independently to each queue.
The SubjectQueueScheduler
ensures that actions from the same subject are processed in order, with a maximum number of concurrent actions per subject. This allows multiple subjects to have their actions processed in parallel, while maintaining order within each subject's actions.
This is useful when you want to process actions from different subjects concurrently, but need to ensure that actions belonging to the same subject are processed in sequence or with limited concurrency.
Extends
Implements
Constructors
Constructor
new SubjectQueueScheduler(init): SubjectQueueScheduler
Creates a new SubjectQueueScheduler.
Parameters
Parameter | Type | Description |
---|---|---|
init | QueueSchedulerInit | Configuration options for the scheduler. |
Returns
SubjectQueueScheduler
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 in its subject's queue and executed when there's room under that subject's concurrency limit.
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject that "owns" the action. |
action | ScheduledAction <any > | The action to be scheduled. |
Returns
void