3 ms·
Just make sure Map access is thread safe - awaiting promises is - but updating/reading map keys usually isn't.
by moonchrome 4y ago
Just make sure Map access is thread safe - awaiting promises is - but updating/reading map keys usually isn't.
- unrealhoang 4y agojs is single-threaded so no problem there.
- moonchrome 4y agoSince OP mentioned Mutexes I assumed he's dealing with multithreaded code, but with JS this works as advertised :)
- skrebbel 4y agoYep, in multithreaded langs you just want to use a ConcurrentMap or whatever the stdlib has for this. The write is very brief because you only write the promise and not eg keep a proper lock on the key until the result has arrived, so no need for a fancier datastructure.