Quirrel4.41.0

types.Thread.wakeup

Method on every thread
thread.wakeup(...): any

Resumes a suspended thread, passing one value back to its suspend call.

examples/types/thread/wakeup-basic.nut
function courierRun() { return suspend() }
let t = newthread(courierRun)
t.call()
println("t.wakeup(\"advance\") =", t.wakeup("advance"))
Output:
t.wakeup("advance") = advance

Parameters

...anyat most the first extra argument is used; the rest are accepted and silently ignored repeats

Return value

Whatever the thread passes to its next suspend, or returns, or null when no value was given for either.

Errors

Throws cannot wakeup a idle thread when the thread has not been started (or already ran to completion) and cannot wakeup a running thread when it is currently executing - only a "suspended" thread can be woken up.

Notes

The signature looks fully variadic, the same shape as types.Function.call, but it is not: t.wakeup(a, b, c) delivers only a to the thread's suspend call, the same as t.wakeup(a) - b and c are read, not checked, and thrown away. Calling with no argument resumes with null, the same as a bare suspend() with nothing passed to it.

An exception that reaches the top of the thread's function uncaught after this call is still delivered to the caller of wakeup as a normal, catchable error, but a host-installed runtime error reporter also reports it straight from inside the thread first - see the Notes on types.Thread.call for details.

Example

examples/types/thread/wakeup.nut
function body() {
    let r = suspend("s1")
    println("thread saw", r)
    return "done"
}
let t = newthread(body)
t.call()
println("t.wakeup(\"a\", \"b\", \"c\") =", t.wakeup("a", "b", "c")) // only "a" reaches suspend(); b, c are dropped
try { t.wakeup() } catch(e) { println("t.wakeup() throws:", e) } // already idle again
Output:
thread saw a
t.wakeup("a", "b", "c") = done
t.wakeup() throws: cannot wakeup a idle thread

See also

suspendPauses the running thread and hands its arguments to whoever resumes it.
wakeupthrowResumes a suspended thread by throwing value at its suspend call, instead of returning from it normally.
getstatusReturns the thread's current state as a string.
threadclass index