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

101
Views
Crear una función auxiliar generalizada que prometa funciones y resuelva con valor devuelto

Estoy tratando de crear una función auxiliar que prometa una función que tome un número arbitrario de argumentos. Intuitivamente, el problema podría abordarse envolviendo resolver con devoluciones de llamada, con lo que siempre he tenido problemas, así que dígame explícitamente cómo hacerlo. Gracias.

 function prom(rawFunc, ...arg){ // This is the helper function return new Promise ((resolve, reject)=>{ checkFn(rawFunc); function checkFn(rawFunc){ if (rawFunc instanceof Function === false){ return reject("Error: rawFunc passed is not a function"); } let returnValue = rawFunc(...arg) resolve(returnValue); } }); } function targetFn1 (a, b){ console.log(`targetFn1 should return ${a+b}`) setTimeout(() => { console.log(`truly returning value ${a+b}`) return a + b }, 4000); // this function returns a+b after a delay of 4 seconds } function targetFn2 (c, d, e){ console.log(c) console.log(d) console.log(e) console.log(`targetFn2 returning ${c+d+e}`) return c+d+e } async function mainFn(){ let value1 = await prom(targetFn1,1,3) let value2 = await prom(targetFn2,value1,3,4); } mainFn(); // console log : // targetFn1 should return 4 // undefined // 3 // 4 // targetFn2 returning NaN // truly returning value 4
about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!