export interface Clock { now ( ) : number ; setInterval ( callback , intervalMs ) : void ; } export class RealClock implements Clock { now ( ) { return Date . now ( ) ; } setInterval ( callback , intervalMs ) { setInterval ( callback , intervalMs ) ; } } export class ManualClock implements Clock { public nowMs = 0 ; private callbacks = [ ] as Function [ ] ; constructor ( ) { } now ( ) { return this . nowMs ; } setInterval ( callback , intervalMs ) { this . callbacks . push ( callback ) ; } async runCallbacks ( ) { for ( const callback of this . callbacks ) { await callback ( ) ; } } }