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

169
Views
Retrun datos de la función cuando se ejecuta

 async function bringData() { return new Promise(resolve => { setTimeout(() => { resolve(con.query('SELECT company, industry FROM my_table', function (err, result) { if (err) { console.error(err); throw 'Error getting data from google_businesses table'; } else { return result; } })); }, 1000); }); } (async () => { // return data from brindData function let getData = await bringData(); console.log(getData); })();

Llamo a esta función en main pero siempre recibo un error. Soy un poco nuevo en el nodo, así que si alguien puede guiarme o si hay alguna otra forma de hacer esto, de modo que cuando obtenga mi resultado pueda devolverlo.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Llame a resolve con el result de su consulta. La con.query parece otra cosa asíncrona:

 con.query('...', (err, result) => { if (!err) resolve(result); });
about 4 years ago · Juan Pablo Isaza Report

0

Puedes probar esto.

 async function bringData() { return new Promise((resolve, reject) => { con.query('SELECT company, industry FROM my_table', (err, result) => { if (err) { reject(err); } resolve(result); }) }); } (async () => { // execute bringData function try { let getData = await bringData(); console.log(getData); } catch (e) { console.error(e); } })();

Editado con tiempo de espera

 async function bringData() { return new Promise((resolve, reject) => { con.query('SELECT company, industry FROM my_table', (err, result) => { if (err) { reject(err); } resolve(result); }) }); } function timeout(seconds = 10) { return new Promise(resolve => { setTimeout(resolve, 10 * 1000) }) } (async () => { // execute bringData function try { await timeout(); let getData = await bringData(); console.log(getData); } catch (e) { console.error(e); } })();

about 4 years ago · Juan Pablo Isaza Report
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!