test-bed-time-service
Version:
A time service for the test-bed, producing messages with real time, fictive time and scenario duration.
50 lines (49 loc) • 2.11 kB
TypeScript
/// <reference types="node" />
import { TimeServiceState } from './states/time-service-states';
import { ICommandOptions } from './index';
import { EventEmitter } from 'events';
import { TimeState, ITiming, ITimingControl } from 'node-test-bed-adapter';
export interface TimeService {
on(event: 'stateUpdated', listener: (state: TimeState) => void): this;
on(event: 'time', listener: (time: ITiming) => void): this;
}
export declare class TimeService extends EventEmitter implements TimeService {
private adapter;
private log;
/** Can be used in clearInterval to reset the timer */
private _timeHandler?;
/** Real-time when the scenario is started */
private _realStartTime?;
/** Real-time of last update */
private _lastTrialTimeUpdate?;
/** The fictive date and time of the simulation / trial as the number of milliseconds
* from the UNIX epoch, 1 January 1970 00:00:00.000 UTC. */
private _trialTime?;
/** Current speed of the simulation in number of times real-time */
private _trialTimeSpeed;
private _state;
/** Interval to send messages to Kafka and browser clients (via Socket.io.). */
private readonly interval;
constructor(options: ICommandOptions);
connect(): Promise<{}>;
/** Allow external services to control transitions. */
transition(msg: ITimingControl): void;
private subscribe;
private handleMessage;
readonly state: TimeServiceState;
trialTime: number | undefined;
trialTimeSpeed: number;
readonly lastUpdateTime: number | undefined;
readonly realStartTime: number | undefined;
/**
* Computes the new Trial Time using the amount of time that has passed since the previous computation of TrialTime
* and the TrialTimeSpeed. Updates the Trial Time accordingly.
*/
progressTrialTime(): number;
startScenario(): void;
stopScenario(): void;
sendTimeUpdate(): void;
sendTimeMessage(timeMsg: ITiming): void;
private startProducingTimeMessages;
private stopProducingTimeMessages;
}