10 examples of '3 sec timer' in JavaScript

Every line of '3 sec 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.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
175function startTimer(secs){
176 timeInSecs = parseInt(secs)-1;
177 ticker = setInterval("tick()",1000); // every second
178}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

131(function timer() {
132 diff = that.duration - Math.floor((Date.now() - start) / 1000);
133
134 if (diff > 0) {
135 that.timeoutId = setTimeout(timer, that.granularity);
136 that.tick(diff);
137 } else {
138 that.running = false;
139 that.tick(0);
140 that.expire();
141 }
142}());
84setSecondsTimer() {
85 this.secondsTimer = setInterval(() => {
86 setSeconds(getSeconds() - 1)
87 this.checkPoint()
88 }, 1000)
89}
36private 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}
61private 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}
10function createTimer(msec) {
11 const queue = [];
12 const timer = setInterval(() => {
13 while (0 < queue.length) {
14 const cb = queue.shift();
15 cb();
16 }
17 }, msec);
18
19 const producer = () => {
20 return new Promise((resolve, reject) => {
21 queue.push(resolve);
22 });
23 };
24
25 producer.clear = () => {
26 clearInterval(timer);
27 };
28
29 return producer;
30}
40getTimerLeft () {
41 if (this.running) {
42 this.stop()
43 this.start()
44 }
45 return this.remaining
46}
125export async function timer(delayMs: number): Promise<Timing> {
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}
18function setTimer(timer, callback, interval) {
19 timers[timer.id] = {
20 callback,
21 interval,
22 lastRun: gameTime
23 };
24}

Related snippets