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
.
Location
rx.js
Scheduler Constructor
##
Scheduler Constructor
##Scheduler Instance Methods
##
Scheduler Instance Methods
##Standard Scheduling ###
Recursive Scheduling ###
Periodic Scheduling ###
`Scheduler Class Methods ##
Scheduler Class Properties
##
Scheduler Class Properties
##Scheduler Constructor ##
Rx.Scheduler(now, schedule, scheduleRelative, scheduleAbsolute)
Rx.Scheduler(now, schedule, scheduleRelative, scheduleAbsolute)
Initializes a new instance of the Rx.Scheduler
. This is meant for Scheduler implementers and not normal usage.
Arguments
now
(Function): Function which gets the current time according to the local machine's system clock.schedule
(Function): Function to schedule an action immediately.scheduleRelative
(Function): Function used to schedule an action in relative time.scheduleAbsolute
(Function): Function used to schedule an action in absolute time.
Example
Location
rx.js
Scheduler Instance Methods ##
Rx.Scheduler.prototype.catch(handler)
Rx.Scheduler.prototype.catch(handler)
Returns a scheduler that wraps the original scheduler, adding exception handling for scheduled actions. There is an alias of catchException
for browsers < IE9.
Arguments
handler
(Function): Handler that's run if an exception is caught. The exception will be rethrown if the handler returnsfalse
.
Returns
(Scheduler): Wrapper around the original scheduler, enforcing exception handling.
Example
Location
rx.js
Rx.Scheduler.prototype.now()
Rx.Scheduler.prototype.now()
Gets the current time according to the Scheduler implementation.
Returns
(Number): The current time according to the Scheduler implementation.
Example
Location
rx.js
Standard Scheduling ###
Rx.Scheduler.prototype.schedule(action)
Rx.Scheduler.prototype.schedule(action)
Schedules an action to be executed.
Arguments
action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.scheduleWithState(state, action)
Rx.Scheduler.prototype.scheduleWithState(state, action)
Schedules an action to be executed with state.
Arguments
state
(Any): State passed to the action to be executed.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.scheduleWithAbsolute(duetime, action)
Rx.Scheduler.prototype.scheduleWithAbsolute(duetime, action)
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
dueTime
(Number): Absolute time at which to execute the action.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.scheduleWithAbsoluteAndState(state, duetime, action)
Rx.Scheduler.prototype.scheduleWithAbsoluteAndState(state, duetime, action)
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
state
(Any): State passed to the action to be executed.dueTime
(Number): Absolute time at which to execute the action.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.scheduleWithRelative(duetime, action)
Rx.Scheduler.prototype.scheduleWithRelative(duetime, action)
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
dueTime
(Number): Relative time at which to execute the action.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.scheduleWithRelativeAndState(state, duetime, action)
Rx.Scheduler.prototype.scheduleWithRelativeAndState(state, duetime, action)
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
state
(Any): State passed to the action to be executed.dueTime
(Number): Relative time at which to execute the action.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Recursive Scheduling ###
Rx.Scheduler.prototype.scheduleRecursive(action)
Rx.Scheduler.prototype.scheduleRecursive(action)
Schedules an action to be executed recursively.
Arguments
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
Location
rx.js
Rx.Scheduler.prototype.scheduleRecursiveWithState(state, action)
Rx.Scheduler.prototype.scheduleRecursiveWithState(state, action)
Schedules an action to be executed with state.
Arguments
state
(Any): State passed to the action to be executed.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
Location
rx.js
Rx.Scheduler.prototype.scheduleRecursiveWithAbsolute(duetime, action)
Rx.Scheduler.prototype.scheduleRecursiveWithAbsolute(duetime, action)
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
dueTime
(Number): Absolute time at which to execute the action for the first time.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
Location
rx.js
Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)
Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)
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
state
(Any): State passed to the action to be executed.dueTime
(Number): Absolute time at which to execute the action for the first time.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
Location
rx.js
Rx.Scheduler.prototype.scheduleRecursiveWithRelative(duetime, action)
Rx.Scheduler.prototype.scheduleRecursiveWithRelative(duetime, action)
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
dueTime
(Number): Relative time at which to execute the action for the first time.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
Location
rx.js
Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)
Rx.Scheduler.prototype.scheduleRecursiveWithAbsoluteAndState(state, duetime, action)
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
state
(Any): State passed to the action to be executed.dueTime
(Number): Relative time at which to execute the action for the first time.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
Location
rx.js
Periodic Scheduling ###
Rx.Scheduler.prototype.schedulePeriodic(period, action)
Rx.Scheduler.prototype.schedulePeriodic(period, action)
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
period
(Number): Period for running the work periodically in ms.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Rx.Scheduler.prototype.schedulePeriodicWithState(state, period, action)
Rx.Scheduler.prototype.schedulePeriodicWithState(state, period, action)
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
state
(Any): State passed to the action to be executed.period
(Number): Period for running the work periodically in ms.action
(Function): Action to execute.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.js
Scheduler Class Methods ##
Rx.Scheduler.normalize(dueTime)
Rx.Scheduler.normalize(dueTime)
Normalizes the specified time span value to a positive value.
Arguments
dueTime
(Number): The time span value to normalize.
Returns
(Number): The specified time span value if it is zero or positive; otherwise, 0
Example
Location
rx.js
Scheduler Class Properties ##
Rx.Scheduler.currentThread
Rx.Scheduler.currentThread
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
Location
rx.js
Rx.Scheduler.immediate
Rx.Scheduler.immediate
Gets a scheduler that schedules work immediately on the current thread.
Example
Location
rx.js
Rx.Scheduler.timeout
Rx.Scheduler.timeout
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, andprocess.nextTick
for older versions.Browser: depending on platform may use
setImmediate
,MessageChannel
,window.postMessage
and for older versions of IE, it will default toscript.onreadystatechanged
, else falls back towindow.setTimeout
.
For all relative and absolute scheduling, it defaults to using window.setTimeout
.
Example
Location
rx.js
Last updated