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

163
Vistas
Javascript equivalent of Task.Yield() in C#

I have a service that can only execute one command at a time. Normally this is fine because users of this service should await the service calls and thus only one service call should begin at a time, however I can't guarantee this will always be the case. Instead, the service waits to finish its last call before it begins the next one. This is what I do in C#:

static async Task<string> Get(string url, params string[] parameters)
{
    while(!isReady)
    {
        await Task.Yield();
    }

    // do stuff
}

I want to do a similar thing in an unrelated NodeJS project.

My Google-fu failed me. Is there a Javascript equivalent of C#'s Task.Yield() that I can await?

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

0

I have a utility function called wait:

export const wait = (millis = 0) =>
    new Promise(resolve => setTimeout(resolve, millis))

while(!isReady)
  await wait()
about 4 years ago · Juan Pablo Isaza Denunciar

0

Ah, of course! It's simple. This might not be the best way but it works.

static async RunCommand(cmd: string, ...params: string[]): Promise<string> {
    while(!this.isReady) {
        await new Promise(resolve => setTimeout(resolve, 0));
    }

    // do stuff
}
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