tur/chan
synchronous and async buffered channels for inter-fiber communication.
Since: Phase T19-C
chan-new
(chan-new [cap :int] :ptr<void>)
allocate a new synchronous blocking channel with the given capacity.
| cap | ring-buffer capacity (number of int64_t slots) |
An opaque ptr<void> handle to the ChanBlock.
(let [ch (chan-new 8)] ...) ; => ptr<void>
Since: Phase T19-C
chan-send
(chan-send [ch :ptr<void> val :int] :nil)
send a value into a synchronous channel, blocking when full.
| ch | channel handle returned by chan-new | |
| val | int64_t value to enqueue |
(chan-send ch 42)
Since: Phase T19-C
chan-recv
(chan-recv [ch :ptr<void>] :int)
receive a value from a synchronous channel, blocking when empty.
| ch | channel handle returned by chan-new |
The next int64_t value dequeued from the channel.
(let [v (chan-recv ch)] ...) ; => int
Since: Phase T19-C
chan-free
(chan-free [ch :ptr<void>] :nil)
destroy a synchronous channel and release all associated memory.
| ch | channel handle returned by chan-new |
(chan-free ch)
Since: Phase T19-C
async-chan-new
(async-chan-new [cap :int] :ptr<void>)
allocate a new async buffered channel with the given capacity.
| cap | ring-buffer capacity (number of int64_t slots) |
An opaque ptr<void> handle to the ChanBlock.
(let [ch (async-chan-new 16)] ...) ; => ptr<void>
Since: Phase T19-D
async-chan-send
(async-chan-send [ch :ptr<void> val :int] :nil)
send a value into an async channel, blocking when full.
| ch | channel handle returned by async-chan-new | |
| val | int64_t value to enqueue |
(async-chan-send ch 99)
Since: Phase T19-D
async-chan-recv
(async-chan-recv [ch :ptr<void>] :int)
receive a value from an async channel, blocking when empty.
| ch | channel handle returned by async-chan-new |
The next int64_t value dequeued from the channel.
(let [v (async-chan-recv ch)] ...) ; => int
Since: Phase T19-D
async-chan-try-send
(async-chan-try-send [ch :ptr<void> val :int] :bool)
attempt to send a value without blocking.
| ch | channel handle returned by async-chan-new | |
| val | int64_t value to enqueue |
true if the value was enqueued; false if the channel was full.
(if (async-chan-try-send ch 7) ...) ; => bool
Since: Phase T19-D
async-chan-try-recv
(async-chan-try-recv [ch :ptr<void>] :int)
attempt to receive a value without blocking.
| ch | channel handle returned by async-chan-new |
The dequeued int64_t value, or INT64_MIN if the channel was empty.
(let [v (async-chan-try-recv ch)] ...) ; => int (INT64_MIN = empty)
Since: Phase T19-D
async-chan-count
(async-chan-count [ch :ptr<void>] :int)
return the number of items currently in an async channel.
| ch | channel handle returned by async-chan-new |
The current item count as an int.
(async-chan-count ch) ; => int
Since: Phase T19-D
async-chan-free
(async-chan-free [ch :ptr<void>] :nil)
destroy an async channel and release all associated memory.
| ch | channel handle returned by async-chan-new |
(async-chan-free ch)
Since: Phase T19-D