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

605
Views
espere el valor de la función de retorno antes de que se active la devolución de llamada

Estoy tratando de crear un módulo que obtenga toda la información una por una y la almacene en una matriz al final, devuelve la matriz, en lugar del bucle que estoy usando recursividad. El problema aquí es que mi función principal no está esperando el valor devuelto, por lo que no se pasa ningún valor en la devolución de llamada. Puedo volver a escribir esta espera asincrónica o promesa, pero si el mismo tipo de problema está presente en todo el proyecto, no quiero volver a escribir todo. Esto puede ser manejado por devoluciones de llamada? o de alguna otra manera puedo resolverlo.

 const GetRequest = require("./getRequest.js"); module.exports = function GetProcessList(environment, token, processCompleteList, callback) { var allProcessDraft = []; var loopMaxRun = processCompleteList.data.length -1; var a = RecursiveGet(environment, token, processCompleteList, allProcessDraft, loopMaxRun); callback(a); //Not waiting for the value } //recursion function to get all the data one by one function RecursiveGet(environment, token, processCompleteList, allProcessDraft, index) { var URL = "https://" + environment + "...../rest/process/versionPage?calledFrom=master&pageNo=0&processMasterId=" + processCompleteList.data[index].id + "&recordsPerPage=10&sortType=DESC"; if (index != 0) { GetRequest(URL, token, function (processDraft) { allProcessDraft.push(processDraft); return RecursiveGet(environment, token, processCompleteList,allProcessDraft, index -1); }); } else { return allProcessDraft; } }
over 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pruebe el siguiente código.

 async function RecursiveGet(environment, token, processCompleteList, allProcessDraft, index) { var URL = "https://" + environment + "...../rest/process/versionPage?calledFrom=master&pageNo=0&processMasterId=" + processCompleteList.data[index].id + "&recordsPerPage=10&sortType=DESC"; if (index != 0) { const processedDraft = await GetRequest(URL, token); allProcessDraft.push(processDraft); return RecursiveGet(environment, token, processCompleteList,allProcessDraft, index -1); } else { return allProcessDraft; } }

nota: asegúrese de que GetRequest sea asíncrono

over 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
Virtual assistant