2 ms·
I think most JS programmers do something along the lines of... function check() { return new Promise(async (resolve, reject) => { for(l
by mywittyname 7y ago
I think most JS programmers do something along the lines of...
function check() {
return new Promise(async (resolve, reject) => {
for(let i = 0; i < 6; ++i) {
if(await doCheck()) {
resolve(true);
}
}
reject();
});
}
or...
async function check() {
for(let i = 0; i < 6; ++i) {
const status = await doCheck();
if(status) {
return status;
}
}
throw new Exception('failed the 6 checks');
}
Though, the same thing could certainly be accomplished with pure promise chains. One could also use the setTimeout method in situations where elapsed time is more important than a fixed number of calls.