Function stakker_async_await::fwd_to_stream_result[][src]

pub fn fwd_to_stream_result<T>(
    core: &mut Core,
    more: Fwd<()>,
    init_capacity: usize
) -> (impl Stream<Item = Result<T, ActorFail>>, Fwd<Option<T>>)

Create a FwdStream pipe which passes through failure

The values sent to the returned Fwd should be any number of Some(value), then finally a None to terminate the stream. These values come out of the stream as Some(Ok(value)) and None. If the stream is not terminated with a None before the Fwd is dropped then that counts as irregular termination and the values Some(Err(ActorFail)) and None will come out of the stream to allow it to handle the failure. This usually indicates that an actor unexpectedly failed. So in normal operation you must make sure that the stream is terminated.

There are three ways to operate this pipe:

  • Send all the data immediately to the returned Fwd. It will be queued until the stream owner is ready to handle it. more can be passed as fwd_nop!() as it is not required.

  • For each message received on more, send a batch of items through the returned Fwd. When the available data is finished, send a None. This lets both ends operate efficiently.

  • For each message received on more, send a single item through the returned Fwd. If there is no more data, send a None. This means that data is only sent when the async/await task requests it.

The init_capacity is the initial capacity of the queue. If you know that you’re going to be sending through batches of a certain size, then pass that size here. Otherwise the queue will expand as necessary, so any sensible value will be okay.