import { Utility } from "./utility" ; export class TimeWait { protected time : number ; protected intervalMs : number ; protected waitTimeMs : number ; param startDelayMs param intervalMs param waitTimeMs constructor ( startDelayMs , intervalMs , waitTimeMs ) { this . time = Date . now ( ) ; this . intervalMs = intervalMs ; this . waitTimeMs = waitTimeMs ; this . time = Date . now ( ) + startDelayMs ; } /**
     * Immediately waits.
     */ /**
     * If time is up it will wait for waitTimeMs.
     * Otherwise it returns immediately.
     * The first time this is called it does immediately wait.
     */ public async waitAtInterval ( ) { const currentTime = Date . now ( ) ; if ( currentTime < this . time ) return ; await Utility . timeout ( this . waitTimeMs ) ; this . time = Date . now ( ) + this . intervalMs ; } }