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

72
Views
Cómo continuar la función después de buscar

Actualmente tengo un script que necesitaba obtener datos:

 fetch("https://data.weather.gov.hk/weatherAPI/opendata/weather.php?dataType=flw&lang=en") .then(r => r.json()) .then(result => console.log(result))

Si tuviera que continuar con el guión, puedo usar estos métodos:

Método 1:

 function stuff(){ ... .then(result => function(){ <code> }) }

Método 2:

 function stuff(){ ... .then(result => fetchcont(result)) } function fetchcont(r){ <code> }

¿Hay alguna manera de que esto se pueda presentar de una manera más ordenada, por ejemplo:

 function stuff(){ ... .then(result => *continue*) <script goes here> }

Gracias por adelantado

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

0

Le sugiero que use async/await en lugar de .then() .

Su código sería algo como:

 // your function need to be async in order to use await keyword async function stuff(){ try { //await const res = await fetch(url); // next line will only execute when above fetch is complete const json = res.json() *Do Your other stuff here* } catch (e) { console.log("Err",e) } }

Puede leer más sobre async/await aquí.

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!