Cannot Denodeify Methods In Node-ftp Module
I am new to both node.js and promise style function call. By looking at an denodeify example at http://runnable.com/Ulatc0QnzUgUAAAK/adapting-node-js-with-q-for-promises, I am tryi
Solution 1:
When you pass
ftpClient.list
to Q.denodefiy
, you are getting the function object, list
from the ftpClient
object. It will be just a function and the relationship with the parent is lost. This is important because, the bound function list
might be dependent on the ftpClient
object. So, you must make sure that link is not broken.
Quoting from the Q.denodeify
docs,
Note that if you have a method that uses the Node.js callback pattern, as opposed to just a function, you will need to bind its this value before passing it to denodeify, like so:
var Kitty = mongoose.model("Kitty"); var findKitties = Q.denodeify(Kitty.find.bind(Kitty));
The better strategy for methods would be to use
Q.nbind
, as shown below.
So, you can fix your code in two ways,
Using
Q.denodeify
andFunction.prototype.bind
, like thisvar ftpList = q.denodeify(ftpClient.list.bind(ftpClient));
Using
Q.nbind
, like thisvar ftpList = q.nbind(ftpClient.list, ftpClient);
Solution 2:
you need to use q.nbind
q.nbind(ftpClient.list, ftpClient);
Post a Comment for "Cannot Denodeify Methods In Node-ftp Module"