Module std/channel.vv
The channel module provides channels for communication and synchronization between concurrent tasks.
Example:
import channel from "std/channel.vv"
let ch = channel.make()
channel.send(ch, "hello")
let msg = try channel.recv(ch, 1000)
Exports
fun make()
extern "native"
Creates a new channel.
Example:
let ch = channel.make()
fun send(chan, data)
extern "native"
Sends data to the channel chan.
Example:
channel.send(chan, data)
fun recv(chan, timeout_ms)
extern "native"
Receives data from the channel chan. Blocks up to timeout_ms milliseconds.
If timeout_ms is 0, it blocks indefinitely without a timeout.
Returns a result object.
Example:
let msg = try channel.recv(chan, 3000)
fun select(chans, timeout_ms)
extern "native"
Waits on multiple channels simultaneously and returns the first available data.
Returns { index = i, value = data } wrapped in a result object.
Example:
let res = try channel.select([ch1, ch2], 3000)