Module std/channel.vv
channel モジュールは、並行タスク間の通信および同期のためのチャネルを提供します。
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"
新しいチャネルを作成します。
Example:
let ch = channel.make()
fun send(chan, data)
extern "native"
データをチャネル chan に送信します。
Example:
channel.send(chan, data)
fun recv(chan, timeout_ms)
extern "native"
チャネル chan からデータを受信します。最大 timeout_ms ミリ秒ブロックします。
timeout_ms が 0 の場合、タイムアウトなしで無期限にブロックします。
結果オブジェクトを返します。
Example:
let msg = try channel.recv(chan, 3000)
fun select(chans, timeout_ms)
extern "native"
複数のチャネルで同時に待機し、最初に利用可能になったデータを返します。
{ index = i, value = data } を結果オブジェクトにラップして返します。
Example:
let res = try channel.select([ch1, ch2], 3000)