News for hackers. Stuff that matters.
Re:Ask HN: What are some cool but obscure data structures yo... by Marazan on Friday July 22, 2022 @07:42AM (#32190900)
Because the computation of Result is _expensive_ and _async_.

So if you get two requests for the computation that computes Result in close succession the Map doesn't have the result in place for the second call and as a result you get no caching effect and make 2 expensive requests.

By caching the Promise instead the second request is caught by the cache and simply awaits the Promise resolving so now you only get 1 expensive request.

There are no comments on this comment yet.