Provides a single-producer single-consumer channel with bounded capacity, optional timeouts on receives, and sentinel return values for full, timeout, and closed states. The ring buffer is implemented in C: sends and receives are constant-time operations, values are delivered in first-in first-out order, and a closed channel drains its buffered values before reporting the closed state. The transport is in-process: both ends of a channel live in the calling R process, which suits the channel to prototyping producer and consumer designs and to testing channel-based logic.
Single-producer single-consumer channels for R: a bounded ring buffer implemented in C, with optional timeouts and sentinel return values for full, timeout, and closed states. The transport is in-process.
install.packages("mizu")
library(mizu)
ch <- mizu_inproc_channel(2)
mizu_send(ch, "a")
mizu_send(ch, 42)
mizu_send(ch, "b") # full: returns the mizu_full sentinel
mizu_recv(ch)
#> [1] "a"
mizu_recv(ch)
#> [1] 42
mizu_recv(ch, timeout = 0) # empty: do not wait
#> <mizu_timeout>
mizu_inproc_close(ch)
MIT