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

pub trait CoroutineSink: Sink + Sized {
    fn coro_sender<I>(
        &mut self,
        iter: I
    ) -> SinkSender<Self::SinkItem, Self, I::IntoIter>
    where
        I: IntoIterator<Item = Self::SinkItem>
; fn coro_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError> { ... }
fn coro_send_cleanup(
        &mut self,
        item: Self::SinkItem
    ) -> Result<Result<(), Self::SinkError>, Dropped> { ... }
fn coro_send_many<I>(
        &mut self,
        iter: I
    ) -> Result<Result<(), Self::SinkError>, Dropped>
    where
        I: IntoIterator<Item = Self::SinkItem>
, { ... } }

An extension trait for Sink.

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

Required methods

fn coro_sender<I>(
    &mut self,
    iter: I
) -> SinkSender<Self::SinkItem, Self, I::IntoIter> where
    I: IntoIterator<Item = Self::SinkItem>, 

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.
Loading content...

Provided methods

fn coro_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError>

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 or if the sink panics internally.

Examples

let (mut sender, mut receiver) = mpsc::channel(1);
let result = Coroutine::new().run(move || {
    corona::spawn(move || {
        sender.coro_send(42).unwrap();
    });
    receiver.coro_next().unwrap()
});
assert_eq!(Some(42), result.unwrap());

fn coro_send_cleanup(
    &mut self,
    item: Self::SinkItem
) -> Result<Result<(), Self::SinkError>, Dropped>

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 or if the sink itself panics.

fn coro_send_many<I>(
    &mut self,
    iter: I
) -> Result<Result<(), Self::SinkError>, Dropped> where
    I: IntoIterator<Item = Self::SinkItem>, 

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 or if the sink panics internally.

Loading content...

Implementors

impl<S: Sink> CoroutineSink for S[src]

fn coro_send(&mut self, item: Self::SinkItem) -> Result<(), Self::SinkError>[src]

fn coro_send_cleanup(
    &mut self,
    item: Self::SinkItem
) -> Result<Result<(), Self::SinkError>, Dropped>
[src]

fn coro_send_many<I>(
    &mut self,
    iter: I
) -> Result<Result<(), Self::SinkError>, Dropped> where
    I: IntoIterator<Item = Self::SinkItem>, 
[src]

Loading content...