> For the complete documentation index, see [llms.txt](https://soufatn.gitbook.io/rxjs-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://soufatn.gitbook.io/rxjs-book/summary/schedulers/scheduler.md).

# Rx.Scheduler

Provides a set of static methods to access commonly used schedulers and a base class for all schedulers.

## Usage #\#

The follow example shows the basic usage of an `Rx.Scheduler`.

```javascript
var disposable = Rx.Scheduler.timeout.scheduleWithState(
     'world',
     function (x) {
          console.log('hello ' + x);
     }
);

// => hello world
```

### Location

* rx.js

## `Scheduler Constructor` #\#

* [`constructor`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulernow-schedule-schedulerelative-scheduleabsolute)

## `Scheduler Instance Methods` #\#

* [`catchException`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypecatchexceptionhandler)
* [`now`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypenow)

### Standard Scheduling ##\#

* [`schedule`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypescheduleaction)
* [`scheduleWithState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithstatestate-action)
* [`scheduleWithAbsolute`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteduetime-action)
* [`scheduleWithAbsoluteAndState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteandstatestate-duetime-action)
* [`scheduleWithRelative`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteduetime-action)
* [`scheduleWithRelativeAndState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteandstatestate-duetime-action)

### Recursive Scheduling ##\#

* [`scheduleRecursive`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerschedulerecursiveaction)
* [`scheduleRecursiveWithState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerschedulerecursivewithstatestate-action)
* [`scheduleRecursiveWithAbsolute`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerecursivewithabsoluteduetime-action)
* [`scheduleRecursiveWithAbsoluteAndState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerecursivewithabsolutewithstatestate-duetime-action)
* [`scheduleRecursiveWithRelative`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerecursivewithrelativeduetime-action)
* [`scheduleRecursiveWithRelativeAndState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerecursivewithrelativewithstatestate-duetime-action)

### Periodic Scheduling ##\#

* [`schedulePeriodic`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypescheduleperiodicperiod-action)
* [`schedulePeriodicWithState`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerscheduleperiodicwithstatestate-period-action)

## \`Scheduler Class Methods #\#

* [`normalize`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulernormalizetimespan)

## `Scheduler Class Properties` #\#

* [`currentThread`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulercurrentthread)
* [`immediate`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerimmediate)
* [`timeout`](/rxjs-book/summary/schedulers/scheduler.md#rxschedulertimeout)

## *Scheduler Constructor* #\#

### `Rx.Scheduler(now, schedule, scheduleRelative, scheduleAbsolute)` <a href="#rxschedulernow-schedule-schedulerelative-scheduleabsolute" id="rxschedulernow-schedule-schedulerelative-scheduleabsolute"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulernow-schedule-schedulerelative-scheduleabsolute) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L5-L9)

Initializes a new instance of the `Rx.Scheduler`. This is meant for Scheduler implementers and not normal usage.

#### Arguments

1. `now` *(Function)*: Function which gets the current time according to the local machine's system clock.
2. `schedule` *(Function)*: Function to schedule an action immediately.
3. `scheduleRelative` *(Function)*: Function used to schedule an action in relative time.
4. `scheduleAbsolute` *(Function)*: Function used to schedule an action in absolute time.

#### Example

```javascript
// Used for scheduling immediately
function schedule(state, action) {
     var scheduler = this,
          disposable = new Rx.SingleAssignmentDisposable();

     var id = setTimeout(function () {
          if (!disposable.isDisposed) {
               disposable.setDisposable(action(scheduler, state));
          }
     }, 0);

     return new CompositeDisposable(disposable, disposableCreate(function () {
          clearMethod(id);
     }));
}

// Used for scheduling relative to now
function scheduleRelative(state, dueTime, action) {
     var scheduler = this,
          dt = Scheduler.normalize(dueTime);

     // Shortcut if already 0
     if (dt === 0) {
          return scheduler.scheduleWithState(state, action);
     }

     var disposable = new Rx.SingleAssignmentDisposable();
     var id = window.setTimeout(function () {
          if (!disposable.isDisposed) {
               disposable.setDisposable(action(scheduler, state));
          }
     }, dt);

     return new CompositeDisposable(disposable, disposableCreate(function () {
          window.clearTimeout(id);
     }));
}

// Used for scheduling in absolute time
function scheduleAbsolute(state, dueTime, action) {
     return this.scheduleWithRelativeAndState(state, dueTime - this.now(), action);
}

var timeoutScheduler = new Rx.Scheduler(
     Date.now,
     schedule,
     scheduleRelative,
     scheduleAbsolute
);

var handle = timeoutScheduler.schedule(function () {
     console.log('hello');
});

// => hello
```

### Location

* rx.js

## *Scheduler Instance Methods* #\#

### `Rx.Scheduler.prototype.catch(handler)` <a href="#rxschedulerprototypecatchhandler" id="rxschedulerprototypecatchhandler"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypecatchhandler) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L65-L72)

Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions. There is an alias of `catchException` for browsers < IE9.

#### Arguments

1. `handler` *(Function)*: Handler that's run if an exception is caught. The exception will be rethrown if the handler returns `false`.

#### Returns

*(Scheduler)*: Wrapper around the original scheduler, enforcing exception handling.

#### Example

```javascript
function inherits (ctor, superCtor) {
    ctor.super_ = superCtor;
    ctor.prototype = Object.create(superCtor.prototype, {
        constructor: {
            value: ctor,
            enumerable: false,
            writable: true,
            configurable: true
        }
    });
}

inherits (SchedulerError, Error);

function SchedulerError(message) {
    Error.call(this, message);
}

var scheduler = Rx.Scheduler.timeout;
var catchScheduler = scheduler.catchException(function (e) {
    return e instanceof SchedulerError;
});

// Throws no exception
var d1 = catchScheduler.schedule(function () {
    throw new SchedulerError('woops');
});

var d2 = catchScheduler.schedule(function () {
    throw new Error('woops');
});

// => Uncaught Error: woops
```

### Location

* rx.js

### `Rx.Scheduler.prototype.now()` <a href="#rxschedulerprototypenow" id="rxschedulerprototypenow"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypenow) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L17-L24)

Gets the current time according to the Scheduler implementation.

#### Returns

*(Number)*: The current time according to the Scheduler implementation.

#### Example

```javascript
var now = Rx.Scheduler.timeout.now();

console.log(now);
// => 1381806323143
```

### Location

* rx.js

### Standard Scheduling ##\#

### `Rx.Scheduler.prototype.schedule(action)` <a href="#rxschedulerprototypescheduleaction" id="rxschedulerprototypescheduleaction"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypescheduleaction) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L112-114)

Schedules an action to be executed.

#### Arguments

1. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.immediate.schedule(function () {
     console.log('hello');
});

// => hello

// Tries to cancel but too late since it is immediate
disposable.dispose();
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleWithState(state, action)` <a href="#rxschedulerprototypeschedulewithstatestate-action" id="rxschedulerprototypeschedulewithstatestate-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithstatestate-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L122-124)

Schedules an action to be executed with state.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.immediate.scheduleWithState('world', function (x) {
     console.log('hello ' + x);
});

// => hello world

// Tries to cancel but too late since it is immediate
disposable.dispose();
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleWithAbsolute(duetime, action)` <a href="#rxschedulerprototypeschedulewithabsoluteduetime-action" id="rxschedulerprototypeschedulewithabsoluteduetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteduetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L153-155)

Schedules an action to be executed at the specified absolute due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `dueTime` *(Number)*: Absolute time at which to execute the action.
2. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleWithAbsolute(
     Date.now() + 5000, /* 5 seconds in the future */
     function () {
          console.log('hello');
     }
);

// => hello
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleWithAbsoluteAndState(state, duetime, action)` <a href="#rxschedulerprototypeschedulewithabsoluteandstatestate-duetime-action" id="rxschedulerprototypeschedulewithabsoluteandstatestate-duetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithabsoluteandstatestate-duetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L164-166)

Schedules an action to be executed at the specified absolute due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `dueTime` *(Number)*: Absolute time at which to execute the action.
3. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleWithAbsolute(
     'world',
     Date.now() + 5000, /* 5 seconds in the future */
     function (x) {
          console.log('hello ' + x);
     }
);

// => hello world
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleWithRelative(duetime, action)` <a href="#rxschedulerprototypeschedulewithrelativeduetime-action" id="rxschedulerprototypeschedulewithrelativeduetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithrelativeduetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L132-134)

Schedules an action to be executed after the specified relative due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `dueTime` *(Number)*: Relative time at which to execute the action.
2. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleWithRelative(
     5000, /* 5 seconds in the future */
     function () {
          console.log('hello');
     }
);

// => hello
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleWithRelativeAndState(state, duetime, action)` <a href="#rxschedulerprototypeschedulewithrelativeandstatestate-duetime-action" id="rxschedulerprototypeschedulewithrelativeandstatestate-duetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulewithrelativeandstatestate-duetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L164-166)

Schedules an action to be executed at the specified relative due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `dueTime` *(Number)*: Relative time at which to execute the action.
3. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleWithAbsolute(
     'world',
     5000, /* 5 seconds in the future */
     function (x) {
          console.log('hello ' + x);
     }
);

// => hello world
```

### Location

* rx.js

### Recursive Scheduling ##\#

### `Rx.Scheduler.prototype.scheduleRecursive(action)` <a href="#rxschedulerprototypeschedulerecursiveaction" id="rxschedulerprototypeschedulerecursiveaction"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypescheduleaction) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L173-179)

Schedules an action to be executed recursively.

#### Arguments

1. `action` *(Function)*: Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var i = 0;

var disposable = Rx.Scheduler.immediate.scheduleRecursive(
     function (self) {
          console.log(i);
          if (++i < 3) {
               self(i);
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleRecursiveWithState(state, action)` <a href="#rxschedulerprototypeschedulerecursivewithstatestate-action" id="rxschedulerprototypeschedulerecursivewithstatestate-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulerecursivewithstatestate-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L122-124)

Schedules an action to be executed with state.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `action` *(Function)*: Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in recursive invocation state.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.immediate.scheduleRecursiveWithState(
     0,
     function (i, self) {
          console.log(i);
          if (++i < 3) {
               self(i);
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleRecursiveWithAbsolute(duetime, action)` <a href="#rxschedulerprototypeschedulerecursivewithabsoluteduetime-action" id="rxschedulerprototypeschedulerecursivewithabsoluteduetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulerecursivewithabsoluteduetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L226-232)

Schedules an action to be executed recursively at a specified absolute due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `dueTime` *(Number)*: Absolute time at which to execute the action for the first time.
2. `action` *(Function)*: Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified absolute time.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var i = 0;

var disposable = Rx.Scheduler.timeout.scheduleRecursiveWithAbsolute(
     Date.now() + 5000, /* 5 seconds in the future */
     function (self) {
          console.log(i);
          if (++i < 3) {
               // Schedule mutliplied by a second by position
               self(Date.now() + (i * 1000));
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)` <a href="#rxschedulerprototypeschedulerecursivewithabsoluteandstatestate-duetime-action" id="rxschedulerprototypeschedulerecursivewithabsoluteandstatestate-duetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulerecursivewithabsoluteandstatestate-duetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L241-L245)

Schedules an action to be executed recursively at a specified absolute due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `dueTime` *(Number)*: Absolute time at which to execute the action for the first time.
3. `action` *(Function)*: Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleRecursiveWithAbsoluteAndState(
     0,
     Date.now() + 5000, /* 5 seconds in the future */
     function (i, self) {
          console.log(i);
          if (++i < 3) {
               // Schedule mutliplied by a second by position
               self(i, Date.now() + (i * 1000));
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleRecursiveWithRelative(duetime, action)` <a href="#rxschedulerprototypeschedulerecursivewithrelativeduetime-action" id="rxschedulerprototypeschedulerecursivewithrelativeduetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulerecursivewithrelativeduetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L199-L205)

Schedules an action to be executed recursively at a specified relative due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `dueTime` *(Number)*: Relative time at which to execute the action for the first time.
2. `action` *(Function)*: Action to execute recursively. The parameter passed to the action is used to trigger recursive scheduling of the action at the specified relative time.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var i = 0;

var disposable = Rx.Scheduler.timeout.scheduleRecursiveWithRelative(
     5000, /* 5 seconds in the future */
     function (self) {
          console.log(i);
          if (++i < 3) {
               // Schedule mutliplied by a second by position
               self(i * 1000);
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)` <a href="#rxschedulerprototypeschedulerecursivewithrelativeandstatestate-duetime-action" id="rxschedulerprototypeschedulerecursivewithrelativeandstatestate-duetime-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypeschedulerecursivewithrelativeandstatestate-duetime-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L214-218)

Schedules an action to be executed recursively at a specified relative due time. Note this only works with the built-in `Rx.Scheduler.timeout` scheduler, as the rest will throw an exception as the framework does not allow for blocking.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `dueTime` *(Number)*: Relative time at which to execute the action for the first time.
3. `action` *(Function)*: Action to execute recursively. The last parameter passed to the action is used to trigger recursive scheduling of the action, passing in the recursive due time and invocation state.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.scheduleRecursiveWithRelativeAndState(
     0,
     5000, /* 5 seconds in the future */
     function (i, self) {
          console.log(i);
          if (++i < 3) {
               // Schedule mutliplied by a second by position
               self(i, i * 1000);
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### Periodic Scheduling ##\#

### `Rx.Scheduler.prototype.schedulePeriodic(period, action)` <a href="#rxschedulerprototypescheduleperiodicperiod-action" id="rxschedulerprototypescheduleperiodicperiod-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerprototypescheduleperiodicperiod-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L85-L89)

Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using `window.setInterval` for the base implementation.

#### Arguments

1. `period` *(Number)*: Period for running the work periodically in ms.
2. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var i = 0;

var disposable = Rx.Scheduler.timeout.schedulePeriodic(
     1000, /* 1 second */
     function () {
          console.log(i);

          // After three times, dispose
          if (++i > 3) {
               disposable.dispose();
          }
});

// => 0
// => 1
// => 2
// => 3
```

### Location

* rx.js

### `Rx.Scheduler.prototype.schedulePeriodicWithState(state, period, action)` <a href="#rxschedulerscheduleperiodicwithstatestate-period-action" id="rxschedulerscheduleperiodicwithstatestate-period-action"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerscheduleperiodicwithstatestate-period-action) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L98-L104)

Schedules a periodic piece of work by dynamically discovering the scheduler's capabilities. The periodic task will be scheduled using `window.setInterval` for the base implementation.

#### Arguments

1. `state` *(Any)*: State passed to the action to be executed.
2. `period` *(Number)*: Period for running the work periodically in ms.
3. `action` *(Function)*: Action to execute.

#### Returns

*(Disposable)*: The disposable object used to cancel the scheduled action (best effort).

#### Example

```javascript
var disposable = Rx.Scheduler.timeout.schedulePeriodicWithState(
     0,
     1000, /* 1 second */
     function (i) {
          console.log(i);

          // After three times, dispose
          if (++i > 3) {
               disposable.dispose();
          }

          return i;
});

// => 0
// => 1
// => 2
// => 3
```

### Location

* rx.js

## *Scheduler Class Methods* #\#

### `Rx.Scheduler.normalize(dueTime)` <a href="#rxschedulernormalizeduetime" id="rxschedulernormalizeduetime"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulernormalizeduetime) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/scheduler.js#L255-L260)

Normalizes the specified time span value to a positive value.

#### Arguments

1. `dueTime` *(Number)*: The time span value to normalize.

#### Returns

*(Number)*: The specified time span value if it is zero or positive; otherwise, 0

#### Example

```javascript
var r1 = Rx.Scheduler.normalize(-1);
console.log(r1);
// => 0

var r2 = Rx.Scheduler.normalize(255);
console.log(r1);
// => 255
```

### Location

* rx.js

## *Scheduler Class Properties* #\#

### `Rx.Scheduler.currentThread` <a href="#rxschedulercurrentthread" id="rxschedulercurrentthread"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulercurrentthread) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/currentthreadscheduler.js#L4-L68)

Gets a scheduler that schedules work as soon as possible on the current thread. This implementation does not support relative and absolute scheduling due to thread blocking required.

#### Example

```javascript
var scheduler = Rx.Scheduler.currentThread;

var disposable = scheduler.scheduleWithState(
     'world',
     function (x) {
          console.log('hello ' + x);
     });

// => hello world
```

### Location

* rx.js

### `Rx.Scheduler.immediate` <a href="#rxschedulerimmediate" id="rxschedulerimmediate"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulerimmediate) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/immediatescheduler.js#L6-L22)

Gets a scheduler that schedules work immediately on the current thread.

#### Example

```javascript
var scheduler = Rx.Scheduler.immediate;

var disposable = scheduler.scheduleRecursiveWithState(
     0,
     function (x, self) {
          console.log(x);
          if (++x < 3) {
               self(x);
          }
     }
);

// => 0
// => 1
// => 2
```

### Location

* rx.js

### `Rx.Scheduler.timeout` <a href="#rxschedulertimeout" id="rxschedulertimeout"></a>

[#](/rxjs-book/summary/schedulers/scheduler.md#rxschedulertimeout) [Ⓢ](https://github.com/Reactive-Extensions/RxJS/blob/master/src/core/disposables/timeoutscheduler.js#L88-L125)

Gets a scheduler that schedules work via a timed callback based upon platform.

For all schedule calls, it defaults to:

* Node.js: uses `setImmediate` for newer builds, and `process.nextTick` for older versions.
* Browser: depending on platform may use `setImmediate`, `MessageChannel`, `window.postMessage` and for older versions of IE, it will default to `script.onreadystatechanged`, else falls back to `window.setTimeout`.

For all relative and absolute scheduling, it defaults to using `window.setTimeout`.

#### Example

```javascript
var scheduler = Rx.Scheduler.timeout;

var disposable = scheduler.scheduleWithState(
     0,
     function (x) {
          console.log(x);
     }
);

// => 0
```

### Location

* rx.js


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://soufatn.gitbook.io/rxjs-book/summary/schedulers/scheduler.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
