I'm trying to allow for both bounded and unbounded channels in an interface and it's rather awkward because UnboundedSender::send
is not async, because it'll never block even the task. However, that complicates trying to treat it equivalent to Sender
, because it subsequently has no Sink
wrapper. Is there any easy way to turn a UnboundedSender
into a Sink
or otherwise get around this issue so I can have a trait that allows both equally easily?
Does the sender-sink crate do what you want?
You could use futures::sink::unfold
:
futures::sink::unfold(tx, |tx, item| futures::future::ready(tx.send(item).map(|()| tx)));
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.