Scheduler

class deprecated

An execution context and a data structure to order tasks and schedule their execution. Provides a notion of (potentially virtual) time, through the now() getter method.

Deprecation Notes

Scheduler is an internal implementation detail of RxJS, and should not be used directly. Rather, create your own class and implement SchedulerLike. Will be made internal in v8.

class Scheduler implements SchedulerLike {
  static now: () => number
  constructor(schedulerActionCtor: typeof Action, now: () => number = Scheduler.now)
  now: () => number
  schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number = 0, state?: T): Subscription
}

Description

Each unit of work in a Scheduler is called an Action.

class Scheduler {
  now(): number;
  schedule(work, delay?, state?): Subscription;
}

Static Properties

Property Type Description
now () => number

Constructor

constructor(schedulerActionCtor: typeof Action, now: () => number = Scheduler.now)

Parameters

schedulerActionCtor

Type: typeof Action.

now

Optional. Default is Scheduler.now.

Type: () => number.

Properties

Property Type Description
now () => number

A getter method that returns a number representing the current time (at the time this function was called) according to the scheduler's own internal clock.

Methods

schedule<T>(work: (this: SchedulerAction<T>, state?: T) => void, delay: number = 0, state?: T): Subscription

Schedules a function, work, for execution. May happen at some point in the future, according to the delay parameter, if specified. May be passed some context object, state, which will be passed to the work function.

Parameters

work

A function representing a task, or some unit of work to be executed by the Scheduler.

delay

Optional. Default is 0.

Time to wait before executing the work, where the time unit is implicit and defined by the Scheduler itself.

state

Optional. Default is undefined.

Some contextual data that the work function uses when called by the Scheduler.

Returns

Subscription: A subscription in order to be able to unsubscribe the scheduled work.

The given arguments will be processed an stored as an Action object in a queue of actions.

© 2015–2021 Google, Inc., Netflix, Inc., Microsoft Corp. and contributors.
Code licensed under an Apache-2.0 License. Documentation licensed under CC BY 4.0.
https://rxjs.dev/api/index/class/Scheduler