Documentation / @eventkit/base / Scheduler
Class: Scheduler
Responsible for managing and observing any execution associated with a set of subjects (like an AsyncObservable or Subscriber). This is largely what enables eventkit objects to observe the asynchronous work that's performed as a result of creating a subscription.
Dependents on this class are typed to accept SchedulerLike
in it's prototype, which means that any class that implements SchedulerLike
can be used as a drop in replacement for this class to alter the asynchronous behavior of eventkit objects. This implementation can be considered what orchestrates the default behavior of eventkit's asynchronous operations.
The default behavior of this class is to instantly execute the action passed to schedule
, but this method can be overridden in an extension of this class to provide a different behavior (i.e. a callback queue or deferring execution).
Extended by
Implements
Constructors
Constructor
new Scheduler(): Scheduler
Returns
Scheduler
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
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
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
schedule()
schedule(subject, action): void
Schedules an action that is "owned" by the subject that will be executed later.
Parameters
Parameter | Type | Description |
---|---|---|
subject | SchedulerSubject | The subject that "owns" the action. |
action | ScheduledAction <any > | The action to be scheduled. |
Returns
void