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

77
Vistas
I have been trying to fetch data from XMLRPC client

This is a piece of code I wrote. I have trouble accessing data from Promise for later purposes.

function forgotPassword(params) {
  return new Promise(function (resolve, reject) {
    return client.methodCall('forgotPassword', params, function (error, value) {
      if (error === null) {
        if (value === true) {
          console.log('Password Sent!!');
          //subpy.kill('SIGINT');
          return resolve('Password Sent!!');
        }
        else {
          console.log('User Not Found!!');
          //subpy.kill('SIGINT');
          return resolve('User Not Found!!');
        }
      }
      else {
        console.log('Error while doing the Operation!!');
        //subpy.kill('SIGINT');
        return reject(error);
      }
    });
  }
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

I suggest you read the docs on Async Functions and Promises.

In this case you can do a few things

new Promise(function (resolve, reject) {
    return client.methodCall('forgotPassword', params, function (error, value) {
      if (error === null) {
        if (value === true) {
          console.log('Password Sent!!');
          //subpy.kill('SIGINT');
          return resolve('Password Sent!!');
        }
        else {
          console.log('User Not Found!!');
          //subpy.kill('SIGINT');
          return resolve('User Not Found!!');
        }
      }
      else {
        console.log('Error while doing the Operation!!');
        //subpy.kill('SIGINT');
        return reject(error);
      }
    });
  })
.then(res => console.log(res))
.catch(rej => console.log(rej));

The then will be called if the resolve is called.

The catch will be called if there is an error or reject is called.

Another way is to use await inside a async function to wait until you get a result from the promise object

function myPromiseFunction(){
    return new Promise(function (resolve, reject) {.....
}

async function myfunction() {
  try {
      var res = await myPromiseFunction(); // waits until result from promise
      console.log(res);
  } catch (error){
      console.log(error);
  }
  
}

myfunction();
about 4 years ago · Juan Pablo Isaza Denunciar
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