10 examples of 'javascript delay timer' in JavaScript

Every line of 'javascript delay 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
368function delay(ms, callback) {
369 var now = +new Date();
370 var tick = now;
371
372 while (tick - now < ms) {
373 tick = +new Date();
374 }
375 callback();
376}
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

36public get delay() {
37 return this._delay;
38}
49set delay(value: number) {
50 value = +value;
51 if (value < 0 || !isFinite(value)) {
52 this.sec.throwError('RangeError', Errors.DelayRangeError);
53 }
54 this._delay = value;
55
56 if (this._running) {
57 this.stop();
58 this.start();
59 }
60}
477delay(ms, label = '') {
478 return new Promise((resolve, reject) => {
479 Scheduler.scheduleCallback(() => { resolve(); }, ms, 'schedulerDelay_' + label);
480 })
481}
62async function delay(millis) {
63 await new Promise(resolve => setTimeout(resolve, millis));
64}
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}
157recovery.timers.setTimeout('timeout', function timeout() {
158 var err = new Error('Failed to reconnect in a timely manner');
159 opts.duration = (+new Date()) - opts.start;
160
161 recovery.emit('reconnect timeout', err, opts);
162 connect(err);
163}, opts['reconnect timeout']);
40getTimerLeft () {
41 if (this.running) {
42 this.stop()
43 this.start()
44 }
45 return this.remaining
46}
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}
21async function delay (ms) {
22 await new Promise((resolve) => setTimeout(resolve, ms))
23}

Related snippets