Closed jnugh closed 11 years ago
In order to understand the use case, can you show me the code where you're using wait.for, and you're calling a method of a function?
Sure thing, with my patch the following works (userModel is a mongoose Model):
var blub = wait.forMethod(userModel, 'find', {
'_id' : mongoose.Types.ObjectId(req.params.id)
});
The following code however:
var blub = wait.for(userModel.find, {
'_id' : mongoose.Types.ObjectId(req.params.id)
});
results in:
TypeError: Object #
THe type of userModel is function obviously.
I created a simple example: https://gist.github.com/gh1234/6338683 Wait.for makes no sense here actually (no callbacks etc.) But the error occures nevertheless.
ok, thanks! I've removed the "if" completely. First arg could be even an Array of async fns, and it would make sense also (example: a jmp table) Anyway, most programming errors will be catched by the 2nd if.
The this context matters even outside of objects, for example when you use waitfor with mongoose, where methods are kind of static.
Example: Mongoose uses the this context in Model.find which is being called without having an instance of Model, however the this namespace referes to different methods which belong to Model.
wait.forMethod checks if obj is an object, in this case waitfor needs to allow function to be passed as well.