sleepAsync
sleepAsync settles after the requested number of milliseconds without blocking an executor thread.
Signature
sleepAsync(ms: u64): Promise<void>Await the returned Promise inside an async function. Code below that await in the same function waits for the delay, while other ready tasks may continue on the executor thread.
For a blocking delay in synchronous code, 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`