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

119
Views
Node.js Response.send no devuelve datos antes de que finalice la función

¿Puede alguien explicarme por qué la siguiente función regresa antes de que finalice retrieve_s3_file()?

El cliente no recibe datos de response.send a continuación. Los datos devueltos por retrieve_s3_file() son correctos (según la salida de la consola), pero primero se envía una respuesta sin datos al cliente.

 app.post("/getJobStatus", function(request, response){ var guid = request.body.job_id; var to_do_list = []; var data_list = []; var completed_list = []; axios.get(job_queue_url + "/list?guid=" + guid) .then(function (res){ console.log("Response from API gateway : "); console.log(res.data); files = res.data; for (let i = 0; i < files.length; i++) { if (files[i] in completed_list) {continue} else { to_do_list.push(files[i]); completed_list.push(files[i]); } } response.send(retrieve_s3_file(to_do_list, guid)); }) .catch(function (error){ console.log(error); });
about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Si retrieve_s3_files es asincrónico , deberá esperar a que se resuelva la promesa antes de poder usar el valor. Puedes cambiar esa última línea a algo como esto:

 retrieve_s3_file(to_do_list, guid).then(val => { response.send(val); }).catch(error => { console.log(error) });

He agregado el método .catch para que pueda manejar cualquier error que ocurra mientras interactúa con s3.

about 4 years ago · Santiago Trujillo 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!