Options
All
  • Public
  • Public/Protected
  • All
Menu

Main export of typed-scheduler. Performs asynchronous task scheduling with options for priority levels, concurrency-limiting, and rate-limiting.

Hierarchy

  • Scheduler

Index

Constructors

constructor

Properties

Private _concurrency

_concurrency: number

Private _normal

_normal: number

Private _rate

_rate: number

Private pending

pending: Set<Promise<void>> = new Set()

Keeps a reference to each Task that is pending execution, or has completed and but not yet satisfied the configured rate.

Private propertyChanged

propertyChanged: EventEmitter = new EventEmitter()

Used internally for signalling state changes in the scheduler across asynchronous contexts.

Private queues

queues: PromiseCompletionSource<void>[][]

Keeps an opaque reference to each Task that has been scheduled for execution.

Accessors

concurrency

concurrency:

Validates and configures the maximum amount of concurrent pending tasks. Automatically signals the scheduler's event loop to immediately process more tasks if the concurrency is increased. If the scheduler is running at capacity and the concurrency is decreased, the concurrency limit is temporarily violated until the required amount of existing pending tasks have completed.

normal

normal:

Validates and configures the normal priority level used for the convenience method scheduleNormal.

priorities

priorities:

Validates and configures the number of priorities this scheduler uses. Automatically resizes the queues based on the new value.

rate

rate:

Validates and configures the period of time for rate limiting. Automatically signals all currently pending tasks to recalculate remaining period of time based on the new value.

Methods

Private concurrencyLimit

  • concurrencyLimit(): Promise<void>

Private execute

  • execute<T, P>(fn: Task<T, P>, ...params: P): Promise<T>
  • Encapsulates a function execution in a Promise<T> that follows its completion.

    Type parameters

    • T

    • P: any[]

    Parameters

    • fn: Task<T, P>
    • Rest ...params: P

    Returns Promise<T>

idle

  • idle(): Promise<void>
  • Returns a promise that resolves when every scheduled Task has completed execution and the required period of time has passed to satisfy the configured rate limit of the scheduler.

    Returns Promise<void>

Private rateLimit

  • rateLimit(): Promise<void>
  • Holds a reference to an executed Task until the configured rate has been satisfied.

    Returns Promise<void>

ready

  • ready(priority?: number): Promise<void>
  • Returns a promise that resolves when a Task scheduled at a given priority would be executed next, if no other tasks with higher priorities are scheduled in the same tick. The lowest priority is used by default, if none is provided.

    Parameters

    • Default value priority: number = this.priorities - 1

    Returns Promise<void>

schedule

  • schedule<T, P>(fn: Task<T, P>, priority: number, ...params: P): Promise<T>
  • Returns a promise that resolves when the scheduled Task is executed. If the function throws an error, the promise will reject. If the function is asynchronous, the returned promise follows its completion.

    Type parameters

    • T

    • P: any[]

    Parameters

    • fn: Task<T, P>
    • priority: number
    • Rest ...params: P

    Returns Promise<T>

scheduleHigh

  • scheduleHigh<T, P>(fn: Task<T, P>, ...params: P): Promise<T>
  • Convenience method to schedule a task at the highest priority.

    Type parameters

    • T

    • P: any[]

    Parameters

    • fn: Task<T, P>
    • Rest ...params: P

    Returns Promise<T>

scheduleLow

  • scheduleLow<T, P>(fn: Task<T, P>, ...params: P): Promise<T>
  • Convenience method to schedule a task at the lowest priority.

    Type parameters

    • T

    • P: any[]

    Parameters

    • fn: Task<T, P>
    • Rest ...params: P

    Returns Promise<T>

scheduleNormal

  • scheduleNormal<T, P>(fn: Task<T, P>, ...params: P): Promise<T>
  • Convenience method to schedule a task at the normal priority.

    Type parameters

    • T

    • P: any[]

    Parameters

    • fn: Task<T, P>
    • Rest ...params: P

    Returns Promise<T>

Legend

  • Module
  • Object literal
  • Variable
  • Function
  • Function with type parameter
  • Index signature
  • Type alias
  • Enumeration
  • Enumeration member
  • Property
  • Method
  • Interface
  • Interface with type parameter
  • Constructor
  • Property
  • Method
  • Index signature
  • Class
  • Class with type parameter
  • Constructor
  • Property
  • Method
  • Accessor
  • Index signature
  • Inherited constructor
  • Inherited property
  • Inherited method
  • Inherited accessor
  • Protected property
  • Protected method
  • Protected accessor
  • Private property
  • Private method
  • Private accessor
  • Static property
  • Static method

Generated using TypeDoc