• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

130
Views
Problema asíncrono/en espera, no devuelve los datos que quiero

Tengo un problema mientras realizo esta función. No representa los valores en el buen orden. Traté de usar async/await, pero tal vez no lo esté usando de manera adecuada. Aquí db es para mySQL.

 function getUserInfo() { db.connect(function (err) { if (err) throw err; db.query("SELECT id FROM game WHERE id = '" + authorId + "'", function (err, result, field) { if (result.length === 0) { var sql = "INSERT INTO game (id, user, coins) VALUES (" + authorId + ", '" + authorName + "', 0)"; db.query(sql, function (err, result) { if (err) throw err; console.log("Données enregistré"); result = 0 return new Promise((resolve) => { if (true) { resolve(result); } }) }); } else { var sql = "SELECT coins FROM game WHERE id = " + authorId + ""; db.query(sql, function (err, result) { if (err) throw err; console.log(result[0].coins); return new Promise((resolve) => { if (true) { resolve(result[0].coins); } }) }); } }) }); } async function operationAsync() { const result = await getUserInfo() console.log(result) } operationAsync()

tengo este resultado:

 undefined Données enregistré

Quiero que se realice la primera función antes de intentar mostrar su resultado.

Alguna idea ?

almost 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error