Skip to content

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 ​

ts
new QueueScheduler(init): QueueScheduler

Creates a new QueueScheduler.

Parameters ​

ParameterTypeDescription
initQueueSchedulerInitConfiguration options for the scheduler.

Returns ​

QueueScheduler

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 and executed when there's room under the 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.