Trait corona::prelude::CoroutineSink [] [src]

pub trait CoroutineSink: Sized {
    type Item;
    type Error;
    fn coro_send(&mut self, item: Self::Item) -> Result<(), Self::Error>;
fn coro_send_cleanup(
        &mut self,
        item: Self::Item
    ) -> Result<Result<(), Self::Error>, Dropped>;
fn coro_send_many<Iter, I>(
        &mut self,
        iter: I
    ) -> Result<Result<(), Self::Error>, Dropped>
    where
        Iter: Iterator<Item = Self::Item>,
        I: IntoIterator<Item = Self::Item, IntoIter = Iter>
;
fn coro_sender<Iter, I>(
        &mut self,
        iter: I
    ) -> SinkSender<Self::Item, Self, Iter>
    where
        Iter: Iterator<Item = Self::Item>,
        I: IntoIterator<Item = Self::Item, IntoIter = Iter>
; }

An extension trait for Sink.

This is automatically implemented for Sinks and adds some convenience methods to them.

Associated Types

The item pushed to a sink.

The error the sink may return.

Required Methods

Sends one item into the sink.

This is similar to Sink::send, but doesn't consume the sink, only borrows it mutably. This is more convenient with the coroutines, because they can wait on something that is not 'static.

Parameters

  • item: The item to be sent.

Panics

If the reactor is dropped before the sending is done.

If it is called outside of a coroutine.

Examples

let mut core = Core::new().unwrap();
let (mut sender, receiver) = mpsc::channel(1);
let coro = Coroutine::with_defaults(core.handle(), move || {
    sender.coro_send(42).unwrap();
});
assert_eq!(42, core.run(receiver.into_future()).unwrap().0.unwrap());

Sends one item into the sink without panicking on dropped reactor.

This sends one item into the sink, similar to coro_send. The difference is it doesn't panic on dropped reactor. Instead, it returns Err(Dropped) and allows manual cleanup of the coroutine.

Parameters

  • item: The item to be sent.

Panics

If it is called outside of a coroutine.

Sends multiple items into the sink.

This is like coro_send_cleanup. However, it sends multiple items instead of one. This is potentially faster than pushing them one by one, since the sink „flushes“ just once after the whole batch.

Parameters

  • iter: Iterator over the items to send.

Panics

If it is called outside of a coroutine.

Creates a future that sends multiple items into the sink.

This is the internal future of coro_send_many. The difference is, it doesn't wait for the future to resolve, only returns it.

It can be used to combine the future with something else, like sending to multiple sinks in parallel.

Parameters

  • iter: The iterator over items to be sent.

Implementors