Every line of 'typescript timer' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
2 export default function timer() 3 { 4 let started_at 5 6 // System nanosecond high-precision time 7 if (process && typeof process.hrtime === 'function') 8 { 9 started_at = process.hrtime() 10 } 11 // Usual millisecond time 12 else 13 { 14 started_at = Date.now() 15 } 16 17 // Stops the timer 18 return function stop() 19 { 20 // System nanosecond high-precision time 21 if (process && typeof process.hrtime === 'function') 22 { 23 const stopped_at = process.hrtime() 24 25 const seconds = stopped_at[0] - started_at[0] 26 const nanos = stopped_at[1] - started_at[1] 27 28 // Convert time to milliseconds 29 return seconds * 1000 + nanos / 1000000 30 } 31 32 // Usual millisecond time 33 return Date.now() - started_at 34 } 35 }
128 systemTimer(timer) { 129 if (timer) { 130 this.internal.systemTimerReference = timer; 131 } 132 return this.internal.systemTimerReference; 133 }
12 start(timer_name) { 13 this.timers[timer_name] = { 14 start: timestamp.now(), 15 stop: undefined, 16 delta: undefined, 17 }; 18 return this.timers[timer_name]; 19 }
8 setTimeout(function timer() { 9 console.log(j); 10 }, i * 1000);
125 export async function timer(delayMs: number): Promise { 126 const start = Date.now(); 127 await sleep(delayMs); 128 const end = Date.now(); 129 return { start, end }; 130 }
33 _setTimeout(callback, time) { 34 this._timer = setTimeout(() => { 35 callback() 36 this._finish = true 37 this._rest = null 38 }, time / this._rate) 39 40 this._finish = false 41 this._time = time 42 this._startTime = new Date() 43 this._callback = callback 44 this._rest = null 45 }
321 function __Timer() { 322 this._start = (new Date).getTime(); 323 }
40 start() { 41 this.running = true 42 this.startTime = new Date() 43 return this 44 }
36 private startTimer() { 37 this.el.classList.remove(`stopped`) 38 this.startTime = Date.now() 39 this.timerInterval = window.setInterval(() => { 40 const timeLeft = this.timeLeftMilliseconds() 41 if (timeLeft <= 0) { 42 this.stopTimer() 43 this.notifyCompletion() 44 } else { 45 this.displayTimeLeft(formattedTimeSeconds(timeLeft)) 46 } 47 }, updateInterval) 48 }
61 private startTimer() { 62 this.el.classList.remove(`stopped`) 63 this.startTime = Date.now() 64 this.timerInterval = window.setInterval(() => { 65 const timeLeft = this.timeLeftMilliseconds() 66 if (timeLeft <= 0) { 67 this.stopTimer() 68 this.notifyCompletion() 69 } else { 70 this.displayTimeLeft(formattedTimeSeconds(timeLeft)) 71 } 72 }, updateIntervalMs) 73 }