Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mapValues bug? throw a TypeError: callback must be a function #1233

Closed
Summer006 opened this issue Jul 12, 2016 · 3 comments
Closed

mapValues bug? throw a TypeError: callback must be a function #1233

Summer006 opened this issue Jul 12, 2016 · 3 comments
Milestone

Comments

@Summer006
Copy link

What version of async are you using?

2.0.0-rc.6

Which environment did the issue occur in (Node version/browser version)

4.2.6

What did you do? Please include a minimal reproducable case illustrating issue.

call mapValues as the example:
async.mapValues({
'a': 'here/log/TEST/123.txt',
'b': 'here/log/TEST/133.txt' },
fs.stat,
function(err, result) {
console.log('statses=', result);
});

What did you expect to happen?
{'a': stat for file a,
'b' : stat for file b }

What was the actual result?
TypeError: callback must be a function
at makeCallback (fs.js:78:11)
at fs.stat (fs.js:826:14)
at /volume1/web/mywebapp/node_modules/async/dist/async.js:5098:13
at replenish (/volume1/web/mywebapp/node_modules/async/dist/async.js:871:21)
at /volume1/web/mywebapp/node_modules/async/dist/async.js:881:15
at eachOfLimit (/volume1/web/mywebapp/node_modules/async/dist/async.js:3952:26)
at mapValuesLimit (/volume1/web/mywebapp/node_modules/async/dist/async.js:5097:9)
at Object.mapValues (/volume1/web/mywebapp/node_modules/async/dist/async.js:930:20)
at /volume1/web/mywebapp/logmanager.js:45:10
at nextTask (/volume1/web/mywebapp/node_modules/async/dist/async.js:6627:18)


BTW, I use async.map , it works good:
async.map([
'here/log/TEST/123.txt',
'here/log/TEST/133.txt' ],
fs.stat,
function(err, result) {
console.log('statses=', result);
});

@megawac
Copy link
Collaborator

megawac commented Jul 12, 2016

The difference is map only passes value, callback whereas mapValues passes value, key, callback

You will need to change your code to something like

async.mapValues({
  'a': 'here/log/TEST/123.txt',
  'b': 'here/log/TEST/133.txt' },
  (value, key, callback) => fs.stat(value, callback),
  function(err, result) {
    console.log('statses=', result);
  }
);

@Summer006
Copy link
Author

Thanks, it works great!
But..... hmmmm, I think the example code (ref: http://caolan.github.io/async/docs.html#.mapValues)
should correct.
again, thank you

@megawac
Copy link
Collaborator

megawac commented Jul 12, 2016

Ohhhh, want to submit a PR fixing that sample code?

@aearly aearly reopened this Jul 12, 2016
@aearly aearly added this to the 2.0 milestone Jul 12, 2016
@aearly aearly closed this as completed in d31dc8e Jul 12, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants