10 examples of 'jest sleep' in JavaScript

Every line of 'jest sleep' 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
10function sleep(ms) {
11 var start = new Date().getTime();
12 while(new Date().getTime() < start + ms);
13}
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

82function sleep (milli) {
83 var date = new Date();
84 var curDate = null;
85 do { curDate = new Date(); }
86 while(curDate-date < milli);
87}
15function sleep(seconds) {
16 let resolve;
17 const p = new Promise(r => resolve=r);
18 setTimeout(resolve, seconds*1000);
19 return p;
20}
180function sleep(miliseconds) {
181 var currentTime = new Date().getTime();
182 while (currentTime + miliseconds >= new Date().getTime()) {
183 }
184}
1297function sleep(ms) {
1298 return new Promise(resolve => setTimeout(resolve, ms));
1299}
194function sleep(milliseconds) {
195 var start = new Date().getTime();
196 for (var i = 0; i < 1e7; i++) {
197 if ((new Date().getTime() - start) > milliseconds){
198 break;
199 }
200 }
201}
9function sleep(seconds) {
10 return new Promise(resolve => setTimeout(resolve, seconds * 1000));
11}
24function sleep(seconds) {
25 return new Promise((resolve) => setTimeout(resolve, 1000 * seconds));
26}
72function sleep(ms) {
73 return new Promise(resolve => setTimeout(resolve, ms));
74}
1465export function sleep(ms) {
1466 const dt = new Date();
1467 dt.setTime(dt.getTime() + ms);
1468 while (new Date().getTime() < dt.getTime()) { }
1469}

Related snippets