Tanguv0.35.0
System & I/O4 exports
Raw Markdown

/thread

OS thread spawning, parallel execution, sleeping, and synchronization.

(use /thread)

Functions & symbols#

await#

function
(await handle) -> Any

Blocks until the spawned OS thread completes and returns its result.

ParameterTypeOptionalDescription
handleThread-FuturerequiredThread handle returned by `thread/spawn`
Returns:Any
(let out (thread/await h))

await-all#

function
(await-all handles) -> Array

Waits for all OS threads in `handles` and collects results in order.

ParameterTypeOptionalDescription
handlesArrayrequiredArray of Thread-Future handles
Returns:Any
(let results (thread/await-all [h1 h2]))

sleep#

function
(sleep duration-ms) -> None

Sleeps the current OS thread for `duration-ms` milliseconds.

ParameterTypeOptionalDescription
duration_msInt | FloatrequiredMilliseconds to sleep
Returns:Any
(thread/sleep 250)

spawn#

function
(spawn func) -> Thread-Future

Spawns an OS thread running `func` and returns a `Thread-Future` handle.

ParameterTypeOptionalDescription
funcFuncrequiredZero-argument closure to run on a dedicated OS thread
Returns:Any
(let h (thread/spawn (Func () (heavy-compute))))