rw_futures_util

Function await_future_with_monitor_error_stream

source
pub async fn await_future_with_monitor_error_stream<T, E, F: Future>(
    peek_stream: &mut Peekable<impl Stream<Item = Result<T, E>> + Unpin>,
    future: F,
) -> Result<F::Output, Option<E>>
Expand description

Await on a future while monitoring on a peekable stream that may return error. The peekable stream is polled at a higher priority than the future.

When the peekable stream returns with a error and end of stream, the future will return the error immediately. Otherwise, it will keep polling the given future.

Return: - Ok(output) as the output of the given future. - Err(None) to indicate that the stream has reached the end. - Err(e) to indicate that the stream returns an error.