Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda