import { Time } from "./time" ; public export class Timeout { public static of ( timeout , time = Time . now ( ) ) { return new Timeout ( timeout , time ) ; } private readonly _timeout : number ; private readonly _time : Time ; private constructor ( timeout , time ) { this . _timeout = timeout ; this . _time = time ; } public get timeout ( ) : number { return this . _timeout ; } public get time ( ) : Time { return this . _time ; } public reset ( time = Time . now ( ) ) { return new Timeout ( this . _timeout , time ) ; } public elapsed ( now = Date . now ( ) ) { return this . _time . elapsed ( now ) ; } public remaining ( now = Date . now ( ) ) { return this . _timeout - this . elapsed ( now ) ; } }