mapLimit without callback only executes "limit" amount of times
See original GitHub issueWhat version of async are you using? 3.1.0
Which environment did the issue occur in (Node version/browser version) node: 10.16.0
What did you do? Please include a minimal reproducible case illustrating issue.
"use strict";
const delay = (timeout) => {
return new Promise((resolve) => {
setTimeout(resolve, timeout);
});
};
const myAsyncFunction = async function () {
return async.mapLimit([1, 2, 3, 4, 5], 3, async (num) => {
await delay(2000);
console.log(num * 2);
return num * 2;
});
};
myAsyncFunction().then((result) => {
console.log(result);
});
https://codepen.io/bertyhell/pen/NWKMRvY?editors=0012
What did you expect to happen? The code should output: 2, 4, 6, 8, 10 Then at the end of the mapLimit the code should log the array: [2, 4, 6, 8, 10]
What was the actual result? The code outputs: 2, 4, 6 The final then is never called, the await on the async.mapLimit just hangs
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:9
Top Results From Across the Web
node.js - What's point of mapLimit? - Stack Overflow
Without mapLimit node will make all the requests at once (if you're ... Just limit number of async operations at a time, so...
Read more >How to use the async.mapLimit function in async - Snyk
To help you get started, we've selected a few async examples, based on popular ways it is used in public projects. ; executeTests(manifest,...
Read more >async - Documentation - GitHub Pages
A callback which is called after all the iteratee functions have finished, ... The same as concat but runs a maximum of limit...
Read more >How to use Async module to control API requests.
We attach a callback and leave the task to complete the execution. ... Limit to perform the maximum number of operations at a...
Read more >async
mapLimit (arr, limit, iterator, callback). The same as map only no more than "limit" iterators will be simultaneously running at any time.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes, then it works: tsconfig.json:
This means async v3 isn’t compatible with typescript for targets < es2017 😭
I thought you detected an async function because no callback method is passed.
Or would that cause breaking changes for people that didn’t pass a callback, but still expected the callback version of the async lib function to be used?
If typescript is compiling
async
functions down to generator function, then Async can’t tell if it’s anasync
function or a callback-accepting function. Can you tell TS to target ES2017 rather than ES2015?The other (ugly) solution is to wrap
async
functions withasyncify
: