DEV Community

Discussion on: Limit concurrent asynchronous calls

Collapse
 
benjaminblack profile image
Benjamin Black • Edited

It's difficult to mentally follow the chain of promises here, because you have an async function (const asyncLimit = async...) which returns an async function (return async function) which itself awaits at least two promises (one in a loop) before resolving.

Note that asyncLimit does not have to be async, as it does not use await; removing async from the function signature would help comprehension a bit, since you would reduce one level of Promise-ception and stay out of limbo.

I guess it doesn't really matter, because the promise returned by asyncLimit can be used by the calling code. But attaching a finally clause to p instead of awaiting it allows the function to return immediately, instead of waiting for p to resolve.

Thread Thread
 
ycmjason profile image
YCM Jason

oh, I mistyped haha! Thanks for catching this!

asyncLimit shouldn't be an async function.