Hiyas. I have a simple app whereby a client is expecting a promise as a result, but upon calling the resolve() method, the promise keeps returning undefined as the result.
The client code:
UsersRepo.findOneAsync({id: id}).then(function(err, result) { console.log("UserService promise resolution", err, result); });
This outputs "null" and "undefined", for err and result, respectively
The code that is doing the work and returning the promise:
findOneAsync: function(args) { var where = ""; //omitted var promise = new Promise(function(resolve, reject) { db.query("Select * from users" + where + " limit 1", function(err, result) { var res = { id: 1, username: 'username', firstName: 'First', lastName: 'Last' }; if(err != null) { console.log("REJECT", err); reject(err); } else { console.log("RESOLVE", res); resolve(null, res); } }); }); return promise; }
As you can see, I'm just returning some static data for this test (the 'res' variable). In the client code, the console statement always prints out:
UserService promise resolution null undefined
I don't get this. It looks like I'm doing everything correctly: calling the resolve() method with the data, and the client code is using .then(function(err, result)) properly, so it seems. Why isn't data being received from the client end?
Thanks for any help!
==>
Solution:
As mentioned below, Bluebird's reject and resolve only take one argument. The first 'null' was only being seen. Changing the code to 'resolve(res)' worked. Thanks guys.