Skip to content

Instantly share code, notes, and snippets.

View roychri's full-sized avatar

Christian Roy roychri

View GitHub Profile
@jcouyang
jcouyang / README.org
Last active May 31, 2024 14:30
Promise All with Limit of Concurrent N

The Promise All Problem

in case of processing a very large array e.g. Promise.all(A_VERY_LARGE_ARRAY_OF_XHR_PROMISE)

which would probably blow you browser memory by trying to send all requests at the same time

solution is limit the concurrent of requests, and wrap promise in thunk

Promise.allConcurrent(2)([()=>fetch('BLAH1'), ()=>fetch('BLAH2'),...()=>fetch('BLAHN')])