Implementing a custom channel with Sink?

In my new library, which will be a sort of an event loop, I'd like to implement an async channel-like functionality that would look something like this:

loop {
   { ... write to a channel if the channel is empty or return Pending }
   { ... get channel data if any and return None or Pending }

I say a library which means I don't wanna use any runtime so it would work with tokio or async-std. Now,

I read about futures::sink::Sink and I think it is what I'm looking for, but I'm not sure I get it. There are no examples of how this actually work in practice and with just a theory I'm pretty lost.

Can I ask a good soul to explain how Sink works and provide a simple example? I appreciate your help.

The short explanation for how to use Sink is that you import the SinkExt trait and use the helpers it provide (most commonly things like send). You may be interested in the Stream page in Tokio's tutorial. It is not about Sink directly, but streams are very similar to sinks.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.