[−][src]Module webdav_handler::corostream
Use an async closure in a coroutine-like way to produce items for a stream.
Example:
#![feature(async_await, await_macro, futures_api)] use futures::{future, Future, Stream, StreamExt}; use futures::executor::block_on; use corostream::CoroStream; let mut strm = CoroStream::<u8, std::io::Error>::new(async move |mut tx| { for i in 0u8..10 { await!(tx.send(i)); } Ok(()) }); let fut = async { let mut count = 0; while let Some(item) = await!(strm.next()) { println!("{:?}", item); count += 1; } assert!(count == 10); }; block_on(fut);
The stream will produce an Item/Error (for 0.1 streams)
or a Result<Item, Error> (for 0.3 streams) 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
| CoroStream | 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. |