/**
 * A countdown which can be restarted and resolves when the provided milliseconds have passed.
 */ export type CountdownInstance = { done : Promise < void > ; restart : ( newDurationMs ? : number ) => void ; forceFinish : ( ) => void ; } ; param { number } ms returns { { done : Promise < void > , restart : ( newDurationMs ? : number ) => void } } example author Adam Dorling
 *  contact export function Countdown ( ms ) { let startTime = Date . now ( ) ; let interval = null ; let resolveTrigger = null ; let duration = ms ; const done = new Promise ( ( resolve ) => ( resolveTrigger = resolve ) ) ; function finish ( ) { clearInterval ( interval ) ; interval = null ; if ( resolveTrigger ) { resolveTrigger ( ) ; resolveTrigger = null ; } } function restart ( newDurationMs ? ) { if ( typeof newDurationMs !== 'undefined' ) { duration = newDurationMs ; } startTime = Date . now ( ) ; } interval = setInterval ( ( ) => { const now = Date . now ( ) ; const deltaT = now - startTime ; if ( deltaT >= duration ) finish ( ) ; } , 10 ) ; return { done , restart , forceFinish : finish } ; }