Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

158
Vistas
Using a fetch promise synchronously

I need a synchronous function (it can be blocking).

I need to use Fetch, and when the promise is ready, I want to return it on the synchronous function.

Everywhere I look I can't find the answer.

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I need a synchronous function

Unlikely.

(it can be blocking).

That is what synchronous means.

Long running blocking functions (including network operations) cause serious usability problems and should be avoided.

I need to use Fetch, and when the promise is ready, I want to return it on the synchronous function.

That is not possible.

XMLHttpRequest has a synchronous mode, although it is deprecated and should not be used.

You can activate it by passing false as the third parameter to open.

xhr.open("METHOD as string", "URL as strong", false);

fetch learned lessons from XMLHttpRequest and did not implement anything similar.


Learn how to deal with asynchronous code instead. The async and await keywords will let you write in in a synchronous style.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can't block the main thread like this, the browser won't allow you(or nodejs, since I don't know which). There's no synchronous way to fetch like that. You can instead use async/await to have your code avoid callbacks. It's probably highly unadvised to do what you want to and there's a better solution, but I can't tell you much more because of lacking context.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda