This is a question.
Sorry if I'm repeating someone, but I couldn't find fast enough anything that answers it. What are the advantages of using this lib over native Promises? Does it make any thread handling or anything? Is it faster? etc.
Thanks in advance.
Promises add a caching layer for results and errors and state machine around your function calls which makes things more stateful and somewhat slower than necessary and they also allow passing the next point of execution around which breaks encapsulation. Async/await helps somewhat with the latter but you can get the best of both world with casync along with this library.
@odahcam
I need to create a ratings report for a client. The client may have 100k ratings.
I queried my DB and fetched all ratings for the company. Now for each rating I need to process the rating. This requires the data from a few more API calls. I could do Promise.all(ratings.map(processRating)) but this would overload my API. With mapLimit I can set a max of 25 calls at a time. Rather than 1000's. Now I don't hit my AWS rate limit.
async function processRatings(ratings = []) {
try {
const results = await async.mapLimit(ratings, 25, processRating);
return results;
} catch (error) {
console.log(error);
}
}
Most helpful comment
@odahcam
I need to create a ratings report for a client. The client may have 100k ratings.
I queried my DB and fetched all ratings for the company. Now for each rating I need to process the rating. This requires the data from a few more API calls. I could do
Promise.all(ratings.map(processRating))but this would overload my API. With mapLimit I can set a max of 25 calls at a time. Rather than 1000's. Now I don't hit my AWS rate limit.