async.mapLimit does not return a Promise
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 12.9.1, npm 6.10.2, browser N/A
What did you do? Please include a minimal reproducable case illustrating issue. Issue has a thread in stackoverflow https://stackoverflow.com/questions/57622495/async-maplimit-with-promise/57659221#57659221
Basically, I have this code:
async = require('async');
let numPromise = async.mapLimit(['1','2','3','4','5'], 3, function(num, callback){
setTimeout(function(){
num = num * 2,
console.log(num);
callback(null, num);
},
2000);
})
numPromise
.then((result) => console.log("success:" + result))
.catch(() => console.log("no success"));
What did you expect to happen? Execute without errors, ‘numPromise’ should contain a Promise. console should log ‘2,4,6,8,10’ and ‘success:2,4,6,8,10’
What was the actual result? It throws an error: TypeError: Cannot read property ‘then’ of undefined
Note: When I use the ‘promise-async’ module instead of ‘async’ then this code works well. Documentation says that async.mapLimit (and others) return a Promise when no callback is supplied, but I get undefined. Couldn’t find any working sample yet (please also see my suggestion on the ‘need samples’ issue).
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:14
Top GitHub Comments
Wrap the
async
function inasyncify
. http://caolan.github.io/async/v3/global.html#AsyncFunction