Expand description
A stream of values which are asynchronously produced, until the source is closed.
Postage channel receivers implement Stream:
use postage::mpsc::channel;
use postage::sink::Sink;
use postage::stream::Stream;
#[tokio::main]
async fn main() {
let (mut tx, mut rx) = channel(16);
tx.send(true).await;
drop(tx);
assert_eq!(Some(true), rx.recv().await);
assert_eq!(None, rx.recv().await);
}
Streams produce Option<T>
. When a None value is recieved, the stream is closed and
will never produce another item. Loops can be concicely written with while let Some(v) = rx.recv().await {}
use postage::mpsc::channel;
use postage::sink::Sink;
use postage::stream::Stream;
#[tokio::main]
async fn main() {
let (mut tx, mut rx) = channel(16);
tx.send(true).await;
tx.send(true).await;
drop(tx);
while let Some(v) = rx.recv().await {
println!("Value received!: {}", v);
}
}
Structs§
- Recv
Future - A future returned by
Stream::recv
.
Enums§
- Poll
Recv - An enum of poll responses that are produced by Stream implementations.
- TryRecv
Error - An error type returned by
Stream::try_recv
, when the stream has no messages, or is closed.
Traits§
- Stream
- An asynchronous stream, which produces a series of messages until closed.