Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
How to promisify a parent class' class method to use in child class async-await method?

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.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!