[][src]Module webdav_handler::async_stream

Use an async closure to produce items for a stream.

Example:

use futures::StreamExt;
use futures::executor::block_on;
use async_stream::AsyncStream;

let mut strm = AsyncStream::<u8, std::io::Error>::new(|mut tx| async move {
    for i in 0u8..10 {
        tx.send(i).await;
    }
    Ok(())
});

let fut = async {
    let mut count = 0;
    while let Some(item) = strm.next().await {
        println!("{:?}", item);
        count += 1;
    }
    assert!(count == 10);
};
block_on(fut);

The stream will produce a Result<Item, Error> where the Item is an item sent with tx.send(item). Any errors returned by the async closure will be returned as an error value on the stream.

On success the async closure should return Ok(()).

Structs

AsyncStream

An abstraction around a future, where the future can internally loop and yield items.

Sender

Type of the sender passed as first argument into the async closure.

SenderFuture

Future returned by the Sender.send() method.