News for hackers. Stuff that matters.
Re:A brief look at async-await by mywittyname on Monday December 09, 2019 @10:14AM (#21743270)
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.

There are no comments on this comment yet.