I have a childClass and limited access to the parentClass. Within one of the childClass methods I need to invoke a parentClass method, getToken(). getToken(), and the rest of the parentClass, is written using callbacks. The child class is written with promises and async-await.
I know that's messy but this is the only spot where there are issues right now and this is what we need to do.
Example of issue
...
try {
// getToken is not promisified yet so it doesn't work
let tokens = await this.getToken();
refreshToken = tokens.refresh_token;
}
...
Can I make a custom "promisifying" function? Something like,
// This isn't correct even if the idea were ok
async promisify(function) {
return new Promise((resolve, reject) => {
function((err, data) => {
if (err) reject(err);
else resolve(data);
})
})
}
Then in my code write:
...
try {
// getToken is maybe promisified
let tokens = await this.promisify(this.getToken());
refreshToken = tokens.refresh_token;
}
...
Or would it looks something like
const util = require('util');
const asyncGetToken = util.promisify(parentClass.getToken);
...
try {
let tokens = await asyncGetToken();
refreshToken = tokens.refresh_token;
}
...
If so, would I have the right instance of the childClass to work with?
I know that's messy but thanks for any tips.