Rx.VirtualTimeScheduler
Base class for providing scheduling in virtual time. This inherits from the Rx.Scheduler
class.
Usage ##
The following shows an example of using the Rx.VirtualTimeScheduler
. In order for this to work, you must implement the add
, toDateTimeOffset
and toRelative
methods as described below.
Location
rx.virtualtime.js
VirtualTimeScheduler Constructor
##
VirtualTimeScheduler Constructor
##VirtualTimeScheduler Instance Methods
##
VirtualTimeScheduler Instance Methods
##VirtualTimeScheduler Instance Properties
##
VirtualTimeScheduler Instance Properties
##VirtualTimeScheduler Protected Abstract Methods
##
VirtualTimeScheduler Protected Abstract Methods
##VirtualTimeScheduler Protected Methods
##
VirtualTimeScheduler Protected Methods
##Inherited Classes ##
VirtualTimeScheduler Constructor ##
Rx.VirtualTimeScheduler(initialClock, comparer)
Rx.VirtualTimeScheduler(initialClock, comparer)
Creates a new virtual time scheduler with the specified initial clock value and absolute time comparer.
Arguments
initialClock
(Function): Initial value for the clock.comparer
(Function): Comparer to determine causality of events based on absolute time.
Example
Location
rx.virtualtime.js
VirtualTimeScheduler Instance Methods ##
Rx.VirtualTimeScheduler.prototype.advanceBy(time)
Rx.VirtualTimeScheduler.prototype.advanceBy(time)
Advances the scheduler's clock by the specified relative time, running all work scheduled for that timespan.
Arguments
time
(Any): Relative time to advance the scheduler's clock by.
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.advanceTo(time)
Rx.VirtualTimeScheduler.prototype.advanceTo(time)
Advances the scheduler's clock to the specified time, running all work till that point.
Arguments
time
(Any): Absolute time to advance the scheduler's clock to.
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.scheduleAbsolute(dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleAbsolute(dueTime, action)
Schedules an action to be executed at dueTime.
Arguments
dueTime
(Any): Absolute time at which to execute the action.action
(Function): Action to be executed.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.scheduleAbsoluteWithState(state, dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleAbsoluteWithState(state, dueTime, action)
Schedules an action to be executed at dueTime.
Arguments
state
: (Any): State passed to the action to be executed.dueTime
(Any): Absolute time at which to execute the action.action
(Function): Action to be executed.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.scheduleRelative(dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleRelative(dueTime, action)
Schedules an action to be executed at dueTime.
Arguments
dueTime
(Any): Relative time after which to execute the action.action
(Function): Action to be executed.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.scheduleRelativeWithState(state, dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleRelativeWithState(state, dueTime, action)
Schedules an action to be executed at dueTime.
Arguments
state
: (Any): State passed to the action to be executed.dueTime
(Any): Relative time after which to execute the action.action
(Function): Action to be executed.
Returns
(Disposable): The disposable object used to cancel the scheduled action (best effort).
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.sleep(time)
Rx.VirtualTimeScheduler.prototype.sleep(time)
Advances the scheduler's clock by the specified relative time.
Arguments
time
(Any): Relative time to advance the scheduler's clock by.
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.start()
Rx.VirtualTimeScheduler.prototype.start()
Starts the virtual time scheduler.
Example
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.stop()
Rx.VirtualTimeScheduler.prototype.stop()
Stops the virtual time scheduler.
Example
Location
rx.virtualtime.js
VirtualTimeScheduler Abstract Protected Methods ##
Rx.VirtualTimeScheduler.prototype.add(absolute, relative)
Rx.VirtualTimeScheduler.prototype.add(absolute, relative)
Adds a relative time value to an absolute time value. This method is used in several methods including scheduleRelativeWithState
, advanceBy
and sleep
.
Arguments
absolute
(Any): Absolute virtual time value.relative
(Any): Relative virtual time value.
Returns
(Any): Resulting absolute virtual time sum value.
Example
One possible implementation could be as simple as the following:
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.toDateTimeOffset(absolute)
Rx.VirtualTimeScheduler.prototype.toDateTimeOffset(absolute)
Converts an absolute time to a number. This is used directly in the now
method on the Rx.Scheduler
Arguments
absolute
(Any): The absolute time to convert.
Returns
(Number): The absolute time in ms.
Example
One possible implementation could be as simple as the following:
Location
rx.virtualtime.js
Rx.VirtualTimeScheduler.prototype.toRelative(timeSpan)
Rx.VirtualTimeScheduler.prototype.toRelative(timeSpan)
Converts the time span number/Date to a relative virtual time value.
Arguments
timeSpan
(Any): The time span number value to convert. This is used directly inscheduleWithRelativeAndState
andscheduleWithAbsoluteAndState
.
Returns
(Number): Corresponding relative virtual time value.
Example
One possible implementation could be as simple as the following:
Location
rx.virtualtime.js
Last updated
Was this helpful?