question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

async.mapLimit does not return a Promise

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:14

github_iconTop GitHub Comments

4reactions
caubcommented, Aug 27, 2019
const async = require('async');
const delay = require('util').promisify(setTimeout);
const numPromise = async.mapLimit(['1','2','3','4','5'], 3, async num => delay(200).then(() => num*2))
// or const numPromise = async.mapLimit(['1','2','3','4','5'], 3, async num => {
//    await delay(200);
//    return num*2;
// })
numPromise.then(console.log)

1reaction
aearlycommented, Nov 25, 2020
Read more comments on GitHub >

github_iconTop Results From Across the Web

async.mapLimit with Promise - node.js - Stack Overflow
You say, "it returns a Promise if I don't supply a callback" but you are still supplying a callback. Leave it out and...
Read more >
How to use the async.mapLimit function in async - Snyk
Use Snyk Code to scan source code in minutes - no build needed - and fix issues ... function(err) { if (err) return...
Read more >
async - Documentation - GitHub Pages
A collection of async functions for manipulating collections, ... Returns: A Promise, if no callback is passed. Source: concatLimit.js, line 5. See: async....
Read more >
Understanding async/await - discord.js Guide
The rejected state means that the Promise encountered an error and could not execute correctly. One important thing to know is that a...
Read more >
Async and Await | The Odin Project
They both get information from a server, process it, and return a promise. ... Since await does not work on the global scope,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found