3 ms·
Maybe I don't understand your response, but a map of promises to handle parallel in-flight requests for the same resource (which the grandparent pitched) is bas
by hombre_fatal 7y ago
Maybe I don't understand your response, but a map of promises to handle parallel in-flight requests for the same resource (which the grandparent pitched) is basically the most elegant yet simple solution to this common problem.
I don't really see how it's a mutex though, you're just returning the same promise to multiple requests. It's far simpler and doesn't use a locking construct.
- inglor 7y agoA promise is a lock in that resolving it is the 'release' and awaiting it is `acquire`. For example: ``` let release; const acquire = new Promise(resolve => release = resolve); (async () => { await acquire; // use here release(); // now others can use it })(); ``` This is a bit different because multiple people can await the lock here so it's like a "one time multicast mutex" making it more akin to condition variables. That said - thinking about it as a mutex is a really backwards way in my opinion.