← index

Task

inherits Object

A detached concurrent task -- the fire-and-forget primitive beneath the structured Async.gather:. Task.spawn: starts one and answers a handle for observing and controlling it: join for the result, cancel for cooperative cancellation, status / done? to poll. Tasks interleave on one scheduler and their I/O overlaps. See docs/internal/ASYNC_ARCH.md.

Class methods

running

A snapshot List of the handles of all still-running detached tasks -- the basis for a user-written join-all.

native

spawn:

Spawn a detached task running the zero-parameter block and answer its handle immediately -- the spawner keeps running.

var t = Task.spawn:{ 21 * 2 };
t.join    "* -> 42

native

Instance methods

cancel

Request cooperative cancellation (a no-op once the task is finished); answers nil. The task raises an uncatchable cancellation at its next checkpoint -- its finally blocks still run -- and joiners observe a catchable error.

var t = Task.spawn:{ Async.sleep:50 };
t.cancel; Async.sleep:5;
t.status    "* -> cancelled

native

done?

True once the task completed normally.

native

join

The task's result, parking the caller until the task finishes if it is still running. Re-raises the task's exception (catchably) if it failed; raises if the task was cancelled, or if a task joins itself.

native

status

One of 'running', 'done', 'failed', 'cancelled'.

native