I try to promisify SFTPWrapper and hit this problem. I am not sure if it happens to other object or not.
So if I just promisify
one SFTPWrapper function, say readdir
, bluebird will have unhandledRejection : "Cannot read property 'readdir' of undefined" error
. I tried util.promisify
, the same error too.
But if promisifyAll(SFTPWrapper) and it work as expected. But why is that ?
---- update -----
The code I use,
var Client = require('ssh2').Client
var conn = new Client()
conn.on('ready', function() {
conn.sftp(async function(err, sftp) {
if (err) throw err
try {
// promisify will have Cannot read property 'readdir' of undefined error
// both bluebird and util have the error
//let readdirAsync = Promise.promisify(sftp.readdir)
let readdirAsync = util.promisify(sftp.readdir)
list = await readdirAsync(remotePathToList)
// Promise.promisifyAll(sftp) work
const sftp2 = Promise.promisifyAll(sftp)
let list = await sftp2.readdirAsync(toRead)