-
-
Notifications
You must be signed in to change notification settings - Fork 71
Promisifying all methods of a ES6 Class instance doesn't seem to work #57
Copy link
Copy link
Closed
Description
The readme example shows it should be possible to promisify all methods in a module.
// Promisify all methods in a module
pify(fs).readFile('package.json', 'utf8').then(data => {
console.log(JSON.parse(data).name);
//=> 'pify'
});
This doesn't seem to work for ES6 class instances:
// test.js
const pify = require('pify');
class MyClass {
myMethod(cb) {
cb(null, 'hello');
}
}
const myClass = new MyClass();
// works
myClass.myMethod((err, str) => console.log(str));
// works
pify(myClass.myMethod)().then(data => console.log(data));
// does not work
pify(myClass).myMethod().then(data => console.log(data));
$ node test.js
hello
D:\sandbox\master-project\test.js:13
pify(myClass).myMethod().then(data => console.log(data));
^
TypeError: pify(...).myMethod is not a function
at Object.<anonymous> (D:\sandbox\master-project\test.js:13:15)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
I'm not sure if this is by design or not though. The example clearly says "Promisify all methods in a module", so maybe it should only be used for CommonJS modules.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels