10 examples of 'javascript delay 1 second' in JavaScript

Every line of 'javascript delay 1 second' 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

477delay(ms, label = '') {
478 return new Promise((resolve, reject) => {
479 Scheduler.scheduleCallback(() => { resolve(); }, ms, 'schedulerDelay_' + label);
480 })
481}
2export async function delay(ms: number) {
3 // tslint:disable-next-line no-string-based-set-timeout
4 return new Promise( resolve => setTimeout(resolve, ms) );
5 // check here why i disable tslint https://github.com/Microsoft/tslint-microsoft-contrib/issues/355
6}
21async function delay (ms) {
22 await new Promise((resolve) => setTimeout(resolve, ms))
23}
25export function delay(millisecond: number): Promise<void> {
26 return new Promise<void>(resolve => setTimeout(resolve, millisecond));
27}
62async function delay(millis) {
63 await new Promise(resolve => setTimeout(resolve, millis));
64}
301function delay(callback, ms) {
302 var timer = 0;
303 return function() {
304 var context = this, args = arguments;
305 clearTimeout(timer);
306 timer = setTimeout(function () {
307 callback.apply(context, args);
308 }, ms || 0);
309 };
310}
44function delay(ms : number){
45 return new Promise(res => setTimeout(res, ms));
46}
160function delay(ms: number) {
161 return new Promise(resolve => {
162 setTimeout(() => {
163 resolve();
164 }, ms);
165 });
166}
111export function delay(ms: number): Promise<void> {
112 return new Promise((res): number =>
113 setTimeout((): void => {
114 res();
115 }, ms)
116 );
117}

Related snippets