Tanguv0.35.0
System & I/O7 exports
Raw Markdown

/coro

Cooperative coroutines (spawn, await, await-all, sleep) and typed channels (channel, send, recv) backed by Tokio.

(use /coro)

Functions & symbols#

await#

function
(coro/await future) -> Any

Awaits an async coroutine or runtime future inside `*runtime*` and returns its resolved value.

ParameterTypeOptionalDescription
futureCoro-FuturerequiredCoroutine or async future handle
Returns:Any
(let res (coro/await fut))

await-all#

function
(coro/await-all futures) -> Array

Concurrently awaits all futures in `futures`, returning their results in order.

ParameterTypeOptionalDescription
futuresArrayrequiredArray of Coro-Future handles
Returns:Any
(let all (coro/await-all [f1 f2]))

channel#

function
(coro/channel) -> Channel

Creates an async FIFO communication channel.

Returns:Any

recv#

function
(coro/recv channel) -> Any

Receives a message from channel, yielding execution until one is available.

ParameterTypeOptionalDescription
channelChannelrequiredChannel to read from
Returns:Any

send#

function
(coro/send channel message) -> ()

Sends a value into the channel.

ParameterTypeOptionalDescription
channelChannelrequiredTarget channel
messageAnyrequiredValue to transmit
Returns:Any

sleep#

function
(coro/sleep millis) -> None

Non-blocking async sleep suspending the current task for `millis` milliseconds.

ParameterTypeOptionalDescription
millisInt | FloatrequiredMilliseconds to yield
Returns:Any
(coro/sleep 50)

spawn#

function
(coro/spawn (Func () ...)) -> Coro-Future

Spawns a non-blocking asynchronous coroutine task returning a `Coro-Future` handle.

ParameterTypeOptionalDescription
fnFuncrequiredZero-argument task function
Returns:Any
(let fut (coro/spawn (Func () (+ 20 22))))