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.
But we need the async function
fnto complete before resolving theasync function (...args) {. Isn't it?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
asyncLimitdoes not have to be async, as it does not useawait; removingasyncfrom 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
asyncLimitcan be used by the calling code. But attaching afinallyclause topinstead ofawaiting it allows the function to return immediately, instead of waiting forpto resolve.oh, I mistyped haha! Thanks for catching this!
asyncLimitshouldn't be an async function.