Skip to content

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 ​

ts
new SubjectQueueScheduler(init): SubjectQueueScheduler

Creates a new SubjectQueueScheduler.

Parameters ​

ParameterTypeDescription
initQueueSchedulerInitConfiguration options for the scheduler.

Returns ​

SubjectQueueScheduler

Overrides ​

Scheduler.constructor

Methods ​

add() ​

ts
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 ​

ParameterTypeDescription
subjectSchedulerSubjectThe subject that "owns" the promise.
promisePromiseLike<void>The promise to be added to the subject.

Returns ​

void

Implementation of ​

SchedulerLike.add

Inherited from ​

Scheduler.add


dispose() ​

ts
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:

  1. All cleanup actions are executed immediately
  2. The method waits for all promises and cleanup actions to resolve
  3. The subject is removed from the scheduler's tracking collections

Parameters ​

ParameterTypeDescription
subjectSchedulerSubjectThe 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 ​

SchedulerLike.dispose

Inherited from ​

Scheduler.dispose


promise() ​

ts
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 ​

ParameterTypeDescription
subjectSchedulerSubjectThe subject whose work is being awaited.

Returns ​

Promise<void>

Implementation of ​

SchedulerLike.promise

Inherited from ​

Scheduler.promise


schedule() ​

ts
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 ​

ParameterTypeDescription
subjectSchedulerSubjectThe subject that "owns" the action.
actionScheduledAction<any>The action to be scheduled.

Returns ​

void

Implementation of ​

SchedulerLike.schedule

Overrides ​

Scheduler.schedule

Released under the MIT License.