News for hackers. Stuff that matters.
Re:Ask HN: What are some cool but obscure data structures yo... by jdthedisciple on Friday July 22, 2022 @04:04AM (#32189700)
You check for if(promiseMap.get(key)) and in the NO case you do promiseMap.delete(key)?

Could you explain why that's necessary? (sorry probs a stupid question)

Re:Ask HN: What are some cool but obscure data structures yo... by ralusek on Friday July 22, 2022 @11:18AM (#32192877)
So if the promise still exists, that means that there is an active call out for a promise using this key already, so we'll just return it. We know this because when the function that is executing finishes, we delete the promise from the map.

A purpose of this might be, let's say you rebuild some structure very frequently, like hundreds of times per second or whatever. You can call this function for a given key as many times as you want while that async process is executing, and it will only execute it once, always returning the same promise.

Re:Ask HN: What are some cool but obscure data structures yo... by aidos on Friday July 22, 2022 @04:52AM (#32189960)
I’m the no case, the promise is created, and then deleted after the function is resolved.

I’m not entirely sure of the use of this pattern where your using a map and deleting the keys as you go - seems like you’d end up doing more work kinda randomly depending on how the keys were added. I’d just relive the whole map when I was done with it.