kabuki | Lightweight actor system built on top of Tokio | Reactive Programming library
kandi X-RAY | kabuki Summary
kandi X-RAY | kabuki Summary
Kabuki provides a simple way to structure concurrent applications built for the Tokio / Futures platform. It is based on the actor model. An actor is a small unit of computation that is used to manage state and resources. It receives messages from other actors and performs some kind of action based on that input. This way, instead of having state and resources accessed concurrently, only a single thread access it and concurrent access is handled through message passing.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of kabuki
kabuki Key Features
kabuki Examples and Code Snippets
Community Discussions
Trending Discussions on kabuki
QUESTION
I'd like to build an Multi-Producer Multi-Consumer (MPMC) channel with different concurrent tasks processing and producing data in it. Some of these tasks have the responsibility to interface with the filesystem or network.
Two examples:
PrintOutput(String)
would be consumed by a logger, a console output, or a GUI.NewJson(String)
would be consumed by a logger or a parser.
To achieve this, I've selected chan
as the MPMC channel provider and tokio
as the system to manage event loops for each listener on the channel.
After reading the example on tokio's site, I began to implement futures::stream::Stream
for chan::Receiver
. This would allow the use of a for each future to listen on the channel. However, the documentation of these two libraries highlights a conflict:
fn poll(&mut self) -> Poll, Self::Error>
Attempt to pull out the next value of this stream, returning None if the stream is finished.
This method, like Future::poll, is the sole method of pulling out a value from a stream. This method must also be run within the context of a task typically and implementors of this trait must ensure that implementations of this method do not block, as it may cause consumers to behave badly.
fn recv(&self) -> Option
Receive a value on this channel.
If this is an asnychronous channel, recv only blocks when the buffer is empty.
If this is a synchronous channel, recv only blocks when the buffer is empty.
If this is a rendezvous channel, recv blocks until a corresponding send sends a value.
For all channels, if the channel is closed and the buffer is empty, then recv always and immediately returns None. (If the buffer is non-empty on a closed channel, then values from the buffer are returned.)
Values are guaranteed to be received in the same order that they are sent.
This operation will never panic! but it can deadlock if the channel is never closed.
chan::Receiver
may block when the buffer is empty, but futures::stream::Stream
expects to never block when polled.
If an empty buffer blocks, there isn't a clear way to confirm that it is empty. How do I check if the buffer is empty to prevent blocking?
Although Kabuki is on my radar and seems to be the most mature of the actor model crates, it almost entirely lacks documentation.
This is my implementation so far:
...ANSWER
Answered 2017-Oct-22 at 13:37The chan
crate provides a chan_select
macro that would allow a non-blocking recv
; but to implement Future
for such primitives you also need to wake up the task when the channel becomes ready (see futures::task::current()
).
You can implement Future
by using existing primitives; implementing new ones is usually more difficult. In this case you probably have to fork chan
to make it Future
compatible.
It seems the multiqueue
crate has a Future
compatible mpmc channel mpmc_fut_queue
.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install kabuki
Rust is installed and managed by the rustup tool. Rust has a 6-week rapid release process and supports a great number of platforms, so there are many builds of Rust available at any time. Please refer rust-lang.org for more information.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page