Rx.VirtualTimeScheduler
Usage ##
/* Comparer required for scheduling priority */
function comparer (x, y) {
if (x > y) { return 1; }
if (x < y) { return -1; }
return 0;
}
var scheduler = new Rx.VirtualTimeScheduler(0, comparer);
/**
* Adds a relative time value to an absolute time value.
* @param {Any} absolute Absolute virtual time value.
* @param {Any} relative Relative virtual time value to add.
* @return {Any} Resulting absolute virtual time sum value.
*/
scheduler.add = function (absolute, relative) {
return absolute + relative;
};
/**
* Converts an absolute time to a number
* @param {Number} The absolute time in ms
* @returns {Number} The absolute time in ms
*/
scheduler.toDateTimeOffset = function (absolute) {
return new Date(absolute).getTime();
};
/**
* Converts the time span number/Date to a relative virtual time value.
* @param {Number} timeSpan TimeSpan value to convert.
* @return {Number} Corresponding relative virtual time value.
*/
scheduler.toRelative = function (timeSpan) {
return timeSpan;
};
// Schedule some time
scheduler.scheduleAbsolute(1, function () { console.log('foo'); });
scheduler.scheduleAbsolute(2, function () { console.log('bar'); });
scheduler.scheduleAbsolute(3, function () { scheduler.stop(); });
// Start the scheduler
scheduler.start();
// => foo
// => bar
// Check the clock once stopped
console.log(scheduler.now());
// => 3
console.log(scheduler.clock);
// => 3Location
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)Arguments
Example
Location
VirtualTimeScheduler Instance Methods ##
Rx.VirtualTimeScheduler.prototype.advanceBy(time)
Rx.VirtualTimeScheduler.prototype.advanceBy(time)Arguments
Example
Location
Rx.VirtualTimeScheduler.prototype.advanceTo(time)
Rx.VirtualTimeScheduler.prototype.advanceTo(time)Arguments
Example
Location
Rx.VirtualTimeScheduler.prototype.scheduleAbsolute(dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleAbsolute(dueTime, action)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.scheduleAbsoluteWithState(state, dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleAbsoluteWithState(state, dueTime, action)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.scheduleRelative(dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleRelative(dueTime, action)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.scheduleRelativeWithState(state, dueTime, action)
Rx.VirtualTimeScheduler.prototype.scheduleRelativeWithState(state, dueTime, action)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.sleep(time)
Rx.VirtualTimeScheduler.prototype.sleep(time)Arguments
Example
Location
Rx.VirtualTimeScheduler.prototype.start()
Rx.VirtualTimeScheduler.prototype.start()Example
Location
Rx.VirtualTimeScheduler.prototype.stop()
Rx.VirtualTimeScheduler.prototype.stop()Example
Location
VirtualTimeScheduler Abstract Protected Methods ##
Rx.VirtualTimeScheduler.prototype.add(absolute, relative)
Rx.VirtualTimeScheduler.prototype.add(absolute, relative)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.toDateTimeOffset(absolute)
Rx.VirtualTimeScheduler.prototype.toDateTimeOffset(absolute)Arguments
Returns
Example
Location
Rx.VirtualTimeScheduler.prototype.toRelative(timeSpan)
Rx.VirtualTimeScheduler.prototype.toRelative(timeSpan)Arguments
Returns
Example
Location
Last updated