Skip to content

sleepAsync ​

sleepAsync se resuelve después de la cantidad solicitada de milisegundos sin bloquear un hilo del executor.

FirmasleepAsync(ms: u64): Promise<void>

Espere la Promise retornada dentro de una función async. El código debajo de ese await en la misma función espera el retraso, mientras otras tasks listas pueden continuar en el hilo del executor.

Para una espera bloqueante en código síncrono, use sleep.

tyrus
import { sleepAsync } from "tyrus:task";

async function main(): Promise<void> {
    print("before delay");
    await sleepAsync(25);
    print("after delay");
}

error

tyrus
import { sleepAsync } from "tyrus:task";

function main(): void {
    await sleepAsync(25); 
}
text
error[async-await-outside-async]: `await` can only be used inside an async function
at /src/main.tyr:4:5
    await sleepAsync(25);
    ^^^^^
help: move this `await` into an `async` function or mark its enclosing function `async`