Reference · Dates

sleep

signature
sleep(num) -> null

What it does

Waits that many milliseconds, then gives null. Other requests run meanwhile: the wait does not hold the server. There is no maximum. In a scheduled job or a tick the wait ends early when the server stops or the program is loaded again, so a loop that runs for ever stops; a request waits its sleep out. It is an effect, like random() and read_file.

Examples

let before = now()let r = sleep(5)print(r, now() - before >= 5)
output
null true

Edge cases

print(sleep(0), sleep(1.5))fn wait_then(v) {    sleep(1)    v}print(wait_then("done"))
output
null nulldone

Errors

A negative number, or anything that is not a number, is a runtime error, not an error value.

this one fails
print(sleep(-1))
output
line 1: `sleep` expects milliseconds (a number >= 0), got int
this one fails
print(sleep("5"))
output
line 1: `sleep` expects milliseconds (a number >= 0), got str

Chaining

It is rarely piped; in a loop it paces work, and in a tick it is what makes the tick slow:

let t = now()for i in range(0, 3) { sleep(2) }print(now() - t >= 6)
output
true
in a program
schedule("every 1m", () => {    for job in pending() {        run(job)        sleep(200)    }})

See also

now, schedule, every, parallel

Thread
8Useful? Like it, or add to its thread below.

Thread 0 posts

On sleep(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo