1 comment

[ 5.0 ms ] story [ 16.0 ms ] thread
I felt really stupid when I wrote this yesterday, which you would NEVER do in C++:

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status === "fulfilled") {
                ....
            }
        }
    }
Like really? We want the processor to test for equality 9 times for "f", "u", "l", "f", "i", "l", "l", "e", "d"? Or is there some built-in optimization for this?

Or should I do this, which feels hacky, but reduces it to 1 equality test?

    const FULFILLED === "f";

    Promise.allSettled(promises, (results) => {
        for(i in results) {
            if(results[i].status[0] === FULFILLED) {
                ....
            }
        }
    }