Single-Producer Single-Consumer Channels

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.


mizu

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.

Installation

install.packages("mizu")

Usage

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)

License

MIT

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("mizu")

0.0.1 by Charlie Gao, 21 days ago


https://github.com/shikokuchuo/mizu-r


Report a bug at https://github.com/shikokuchuo/mizu-r/issues


Browse source code at https://github.com/cran/mizu


Authors: Charlie Gao [aut, cre] , Posit Software , PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>)


Documentation:   PDF Manual  


MIT + file LICENSE license


Suggests testthat


See at CRAN