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.

Should nodeify handle additional parameters for callbacks

See original GitHub issue

I asked a question on StackOverflow seeking help with dealing with the callback for a passport.js strategy callback.

The strategy callback allows an optional parameter which can be used as a flash message.

// This strategy is used by passport to handle logins
module.exports.localStrategy = new LocalStrategy(function(username, password, done) {
  users.findOneAsync({username: username}).bind({})
    .then(function(user) {
        if (!user) {
          throw new NoMatchedUserError('Incorrect username.');
          //should be equivalent to:
          // return done(null, false, {message:'something'});
        }
        this.user = user;
        return compare(password, user.password);
    })
    .then(function(isMatch) {
      if (isMatch) {
        return this.user;
        //is equivalent to:
        // return done(null, this.user);
      }
      else {
        throw { message: 'Incorrect password.' };
        //should be equivalent to:
        // return done(null, false, {message:'something else'};
      }
    })
    .nodeify(done);
});

Benjamin Gruenbaum suggested on that question that this might be a feature worth adding in

My JS chops fall way short of knowing where to start on implementing this so apologies for suggesting work for others! Really interested to watch commits to see the shape this might take…

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
petkaantonovcommented, May 31, 2014

Implemented for 2.0

0reactions
petkaantonovcommented, May 29, 2014
Promise.resolve([1,2,3]).nodeify(function(err, a, b, c) {
    // a is [1,2,3]
    // b is undefined
    // c is undefined
})

Promise.resolve([1,2,3]).nodeify(function(err, a, b, c) {
    // a is 1
    // b is 2
    // c is 3
}, {spread: true})
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to pass a third argument to a callback using Bluebird.js ...
by calling nodeify(done) I can handle the path where passwords match but I don't know how to pass the optional third parameter out...
Read more >
How to deal with nested callbacks and avoid “callback hell”
The callback will always have two arguments. And these arguments are in the same order. (Error first, followed by whatever you're interested in) ......
Read more >
ROS2 rclpy Parameter Callback [Tutorial]
Learn how to use a rclpy parameter callback in ROS2. ... Hence we need to add a callback to notify the node as...
Read more >
then/nodeify: Convert promised code to use node style callbacks
Call nodeify directly passing the promise and an optional callback as arguments. If a callback is provided it will be called as callback(error,...
Read more >
Callback Functions in JavaScript - Impressive Webs
This method accepts two arguments: The speed of the fade-in and an optional callback function. In that function you can put whatever you ......
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