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.