Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

197
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda