wait-promise
Make a promise, waiting for a specified amount of time, util something is done. Syntactic sugar for setTimeout and setInterval. Based on ES6 Promise.
Use it in nodeJS
A version compiled to ES5 in CJS format is published to npm as wait-promise.
npm install wait-promise
in ES5:
var wait = ;
in ES6/7:
;
Use it on browser
wait-promise CDN
You can use it with any AMD loader or standalone
var promise = wait; promise;
API Doc
check
wait.check(condition) always returns a promise. If condition throws error or returns false
value explicitly, the promise will be rejected.
let i = 1;let promise = wait;promise;
until
wait.until(condition)
Check condition async and re-check every 100ms until it neighter throws error nor returns false
.
let i = 0;let promise = wait;promise;
With async/wait
let until = waituntil; { let i = 0; await ; ;}
till
wait.till(condition)
Check condition async and re-check every 100ms till it explicitly returns true
. If condition throws error, the promise will be rejected.
let i = 0;let promise = wait;promise;
before
wait.before(millisec).until(condition)
Check condition in millisec
. If time out, the promise will be rejected.
let i = 0;let promise = wait;promise;
after
wait.after(millisec).check(condition)
Check condition after millisec
.
let i = 1;; let promise = wait;
limit
Check condition with limit times. If exceed the limit, the promise will be rejected.
let i = 0;let p = wait;return p;
every
wait.every(millisec[,limit]).until(condition)
Change time interval from 100ms to millisec
。
let i = 0;let promise = wait;promise;
every with limit
wait.every(1, 10)
is equal to wait.every(1).limit(10)
let i = 0;let p = wait;p;
and
wait.every(millisec).and(func).until(condition)
Check every millisec time and do something before checking condition.
{ let i = 0 j = 0; await ; await ; console; //will be 8}
sleep
wait.sleep(millisec)
Do nothing but sleep millisec
var promise = wait;promise;
With async/await
let sleep = waitsleep; { await ; ;}