10 examples of 'js promise wait' in JavaScript

Every line of 'js promise wait' 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
69export function promiseWait() {
70 var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
71 return new Promise(function (res) {
72 return setTimeout(res, ms);
73 });
74}
108function promiseWait() {
109 var ms = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
110 return new Promise(function (res) {
111 return setTimeout(res, ms);
112 });
113}
80export function promiseWait(ms: number = 0): Promise {
81 return new Promise(res => setTimeout(res, ms));
82}
128function waitPromise() {
129 return new Promise(function(resolve) {
130 setTimeout(function() {
131 resolve(true);
132 }, 300);
133 });
134}
137function waitPromise() {
138 return new Promise(function(resolve) {
139 setTimeout(function() {
140 resolve(true);
141 }, 1000);
142 });
143}
1export default function wait(t = 100, val?: any) {
2 return new Promise((resolve) => setTimeout(resolve, t, val));
3}
892function wait0(): Promise {
893 return new Promise(resolve => {
894 setTimeout(resolve, 0);
895 });
896}
198wait() {
199 return this.promise;
200}
22async wait(n) {
23 await new Promise(resolve => this.waits.add([this.count + n, resolve]));
24}
262function wait(cond: () => boolean, timeout: number = 0, intervall: number = 100): Promise {
263 return new Promise((resolve, reject) => {
264 let counter = 0;
265 const timer = setInterval(() => {
266 if (cond()) {
267 clearInterval(timer);
268 resolve();
269 return;
270 }
271 if (timeout > 0 && ++counter * intervall >= timeout) {
272 clearInterval(timer);
273 debug(`getting connection timed out`);
274 reject(new Error('timeout reached'));
275 return;
276 }
277 }, intervall);
278 });
279}

Related snippets