I can't seem to figure out why my promise never resolves when I pass it a function. I have a class method like this:
test(){
return this.dbCollection.insert(...);
}
Which is inserting some data into a MongoDB collection via Monk. It returns a promise. I'm calling this method from another class like this:
var testClass = new TestClass();
testClass.test().onResolve(...);
Here's where I'm hitting trouble. If I do this:
testClass.test().onResolve(console.log('Resolved!'));
The promise resolves, I see "Resolved!" in the console, and everything works as expected. If I check using the MongoDB console, I can see the data was indeed inserted. However, if I do this:
testClass.test().onResolve(function(err, data){
console.log('Resolved!');
});
The promise never resolves, nothing is printed to the console, but the data is still inserted. Has anyone ever seen this behavior before? I believe it's an issue with mpromise, so I tagged Mongoose since it uses the same package for promises.
Thanks for the help @Bergi. Like you suggested, the promise wasn't actually resolving. It turned out to be a problem with mpromise's all()
method (i.e. apparently I don't fully understand how it works). test()
was returning an aggregation of promises using all()
, and that's what wasn't resolving. When that was taken out of the equation, everything worked as expected. Now to figure out what's going on with all()
...