Atom

task.wait()

Waits for one task result.

Signature

task.wait(handle[, timeout])

Parameters

Task, optional timeout in seconds or null, default unlimited.

Returns

Copied worker result, read/write result or null for a timer.

Behavior

Blocks the caller until ready, interrupted or timed out. Coroutine values are driven by resume.

Errors

Timeout, cancellation, foreign handle, worker failure or result transfer failure.

Example

Atom
use task
assert(task.wait(task.after(0), 1) == null)

Wait for a worker result

Start a worker and collect the value its function returns.

Atom
use task
func double(value):
    return value * 2

print(task.wait(task.spawn(double, 4)))
Output
8

The caller waits until the worker returns its value.

Wait for a timer

A timer finishes without a result value.

Atom
use task
print(task.wait(task.after(0)) == null)
Output
true

The completed timer yields null.