[−][src]Struct async_std::sync::Receiver
new channel api at async_std::channel
unstable only.The receiving side of a channel.
This type receives messages by calling recv. But it also implements the Stream trait,
which means it can act as an asynchronous iterator. This struct is created by the channel
function. See its documentation for more.
Examples
#![allow(deprecated)] use std::time::Duration; use async_std::sync::channel; use async_std::task; let (s, r) = channel(100); task::spawn(async move { s.send(1usize).await; task::sleep(Duration::from_secs(1)).await; s.send(2).await; }); assert_eq!(r.recv().await?, 1); // Received immediately. assert_eq!(r.recv().await?, 2); // Received after 1 second.
Implementations
impl<T> Receiver<T>[src]
pub async fn recv<'_>(&'_ self) -> Result<T, RecvError>[src]
Receives a message from the channel.
If the channel is empty and still has senders, this method will wait until a message is sent into it. Once all senders have been dropped it will return RecvError.
Examples
#![allow(deprecated)] use async_std::sync::channel; use async_std::task; let (s, r) = channel(1); task::spawn(async move { s.send(1usize).await; s.send(2).await; // Then we drop the sender }); assert_eq!(r.recv().await?, 1); assert_eq!(r.recv().await?, 2); assert!(r.recv().await.is_err());
pub fn try_recv(&self) -> Result<T, TryRecvError>[src]
Attempts to receive a message from the channel.
If the channel is empty, this method will return an error.
Examples
#![allow(deprecated)] use async_std::sync::channel; let (s, r) = channel(1); s.send(1u8).await; assert!(r.try_recv().is_ok()); assert!(r.try_recv().is_err());
pub fn capacity(&self) -> usize[src]
Returns the channel capacity.
Examples
#![allow(deprecated)] use async_std::sync::channel; let (_, r) = channel::<i32>(5); assert_eq!(r.capacity(), 5);
pub fn is_empty(&self) -> bool[src]
Returns true if the channel is empty.
Examples
#![allow(deprecated)] use async_std::sync::channel; let (s, r) = channel(1); assert!(r.is_empty()); s.send(0).await; assert!(!r.is_empty());
pub fn is_full(&self) -> bool[src]
Returns true if the channel is full.
Examples
#![allow(deprecated)] use async_std::sync::channel; let (s, r) = channel(1); assert!(!r.is_full()); s.send(0).await; assert!(r.is_full());
pub fn len(&self) -> usize[src]
Returns the number of messages in the channel.
Examples
#![allow(deprecated)] use async_std::sync::channel; let (s, r) = channel(2); assert_eq!(r.len(), 0); s.send(1).await; s.send(2).await; assert_eq!(r.len(), 2);
Trait Implementations
impl<T> Clone for Receiver<T>[src]
impl<T> Debug for Receiver<T>[src]
impl<T> Drop for Receiver<T>[src]
impl<T> Stream for Receiver<T>[src]
type Item = T
The type of items yielded by this stream.
pub fn poll_next(
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Option<Self::Item>>[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>
) -> Poll<Option<Self::Item>>
pub fn next(&mut self) -> ImplFuture<Option<Self::Item>> where
Self: Unpin, [src]
Self: Unpin,
pub fn take(self, n: usize) -> Take<Self> where
Self: Sized, [src]
Self: Sized,
pub fn take_while<P>(self, predicate: P) -> TakeWhile<Self, P> where
Self: Sized,
P: FnMut(&Self::Item) -> bool, [src]
Self: Sized,
P: FnMut(&Self::Item) -> bool,
pub fn throttle(self, d: Duration) -> Throttle<Self> where
Self: Sized, [src]
Self: Sized,
pub fn step_by(self, step: usize) -> StepBy<Self> where
Self: Sized, [src]
Self: Sized,
pub fn chain<U>(self, other: U) -> Chain<Self, U> where
Self: Sized,
U: Stream<Item = Self::Item> + Sized, [src]
Self: Sized,
U: Stream<Item = Self::Item> + Sized,
pub fn cloned<'a, T>(self) -> Cloned<Self> where
Self: Sized + Stream<Item = &'a T>,
T: Clone + 'a, [src]
Self: Sized + Stream<Item = &'a T>,
T: Clone + 'a,
pub fn copied<'a, T>(self) -> Copied<Self> where
Self: Sized + Stream<Item = &'a T>,
T: Copy + 'a, [src]
Self: Sized + Stream<Item = &'a T>,
T: Copy + 'a,
pub fn cycle(self) -> Cycle<Self> where
Self: Clone + Sized, [src]
Self: Clone + Sized,
pub fn enumerate(self) -> Enumerate<Self> where
Self: Sized, [src]
Self: Sized,
pub fn delay(self, dur: Duration) -> Delay<Self> where
Self: Sized, [src]
Self: Sized,
pub fn map<B, F>(self, f: F) -> Map<Self, F> where
Self: Sized,
F: FnMut(Self::Item) -> B, [src]
Self: Sized,
F: FnMut(Self::Item) -> B,
pub fn inspect<F>(self, f: F) -> Inspect<Self, F> where
Self: Sized,
F: FnMut(&Self::Item), [src]
Self: Sized,
F: FnMut(&Self::Item),
pub fn last(self) -> ImplFuture<Option<Self::Item>> where
Self: Sized, [src]
Self: Sized,
pub fn fuse(self) -> Fuse<Self> where
Self: Sized, [src]
Self: Sized,
pub fn filter<P>(self, predicate: P) -> Filter<Self, P> where
Self: Sized,
P: FnMut(&Self::Item) -> bool, [src]
Self: Sized,
P: FnMut(&Self::Item) -> bool,
pub fn flat_map<U, F>(self, f: F) -> FlatMap<Self, U, F> where
Self: Sized,
U: IntoStream,
F: FnMut(Self::Item) -> U, [src]
Self: Sized,
U: IntoStream,
F: FnMut(Self::Item) -> U,
pub fn flatten(self) -> Flatten<Self> where
Self: Sized,
Self::Item: IntoStream, [src]
Self: Sized,
Self::Item: IntoStream,
pub fn filter_map<B, F>(self, f: F) -> FilterMap<Self, F> where
Self: Sized,
F: FnMut(Self::Item) -> Option<B>, [src]
Self: Sized,
F: FnMut(Self::Item) -> Option<B>,
pub fn min_by_key<B, F>(self, key_by: F) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B, [src]
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
pub fn max_by_key<B, F>(self, key_by: F) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B, [src]
Self: Sized,
B: Ord,
F: FnMut(&Self::Item) -> B,
pub fn min_by<F>(self, compare: F) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering, [src]
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
pub fn max(self) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
Self::Item: Ord, [src]
Self: Sized,
Self::Item: Ord,
pub fn min(self) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
Self::Item: Ord, [src]
Self: Sized,
Self::Item: Ord,
pub fn max_by<F>(self, compare: F) -> ImplFuture<Option<Self::Item>> where
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering, [src]
Self: Sized,
F: FnMut(&Self::Item, &Self::Item) -> Ordering,
pub fn nth(&mut self, n: usize) -> ImplFuture<Option<Self::Item>> where
Self: Unpin + Sized, [src]
Self: Unpin + Sized,
pub fn all<F>(&mut self, f: F) -> ImplFuture<bool> where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool, [src]
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
pub fn find<P>(&mut self, p: P) -> ImplFuture<Option<Self::Item>> where
Self: Unpin + Sized,
P: FnMut(&Self::Item) -> bool, [src]
Self: Unpin + Sized,
P: FnMut(&Self::Item) -> bool,
pub fn find_map<F, B>(&mut self, f: F) -> ImplFuture<Option<B>> where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Option<B>, [src]
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Option<B>,
pub fn fold<B, F>(self, init: B, f: F) -> ImplFuture<B> where
Self: Sized,
F: FnMut(B, Self::Item) -> B, [src]
Self: Sized,
F: FnMut(B, Self::Item) -> B,
pub fn partition<B, F>(self, f: F) -> ImplFuture<(B, B)> where
Self: Sized,
F: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>, [src]
Self: Sized,
F: FnMut(&Self::Item) -> bool,
B: Default + Extend<Self::Item>,
pub fn for_each<F>(self, f: F) -> ImplFuture<()> where
Self: Sized,
F: FnMut(Self::Item), [src]
Self: Sized,
F: FnMut(Self::Item),
pub fn any<F>(&mut self, f: F) -> ImplFuture<bool> where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool, [src]
Self: Unpin + Sized,
F: FnMut(Self::Item) -> bool,
pub fn by_ref(&mut self) -> &mut Self[src]
pub fn scan<St, B, F>(self, initial_state: St, f: F) -> Scan<Self, St, F> where
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>, [src]
Self: Sized,
F: FnMut(&mut St, Self::Item) -> Option<B>,
pub fn skip_while<P>(self, predicate: P) -> SkipWhile<Self, P> where
Self: Sized,
P: FnMut(&Self::Item) -> bool, [src]
Self: Sized,
P: FnMut(&Self::Item) -> bool,
pub fn skip(self, n: usize) -> Skip<Self> where
Self: Sized, [src]
Self: Sized,
pub fn timeout(self, dur: Duration) -> Timeout<Self> where
Self: Stream + Sized, [src]
Self: Stream + Sized,
pub fn try_fold<B, F, T, E>(
&mut self,
init: T,
f: F
) -> ImplFuture<Result<T, E>> where
Self: Unpin + Sized,
F: FnMut(B, Self::Item) -> Result<T, E>, [src]
&mut self,
init: T,
f: F
) -> ImplFuture<Result<T, E>> where
Self: Unpin + Sized,
F: FnMut(B, Self::Item) -> Result<T, E>,
pub fn try_for_each<F, E>(&mut self, f: F) -> ImplFuture<E> where
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Result<(), E>, [src]
Self: Unpin + Sized,
F: FnMut(Self::Item) -> Result<(), E>,
pub fn zip<U>(self, other: U) -> Zip<Self, U> where
Self: Sized,
U: Stream, [src]
Self: Sized,
U: Stream,
pub fn unzip<A, B, FromA, FromB>(self) -> ImplFuture<(FromA, FromB)> where
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Stream<Item = (A, B)> + Sized, [src]
FromA: Default + Extend<A>,
FromB: Default + Extend<B>,
Self: Stream<Item = (A, B)> + Sized,
pub fn collect<'a, B>(self) -> ImplFuture<B> where
Self: Sized + 'a + Send,
B: FromStream<Self::Item>,
Self::Item: Send, [src]
Self: Sized + 'a + Send,
B: FromStream<Self::Item>,
Self::Item: Send,
pub fn merge<U>(self, other: U) -> Merge<Self, U> where
Self: Sized,
U: Stream<Item = Self::Item> + Sized, [src]
Self: Sized,
U: Stream<Item = Self::Item> + Sized,
pub fn partial_cmp<S>(self, other: S) -> ImplFuture<Option<Ordering>> where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>,
pub fn position<P>(&mut self, predicate: P) -> ImplFuture<Option<usize>> where
Self: Unpin + Sized,
P: FnMut(Self::Item) -> bool, [src]
Self: Unpin + Sized,
P: FnMut(Self::Item) -> bool,
pub fn cmp<S>(self, other: S) -> ImplFuture<Ordering> where
Self: Sized + Stream,
S: Stream,
Self::Item: Ord, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: Ord,
pub fn count(self) -> ImplFuture<usize> where
Self: Sized, [src]
Self: Sized,
pub fn ne<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized,
S: Sized + Stream,
Self::Item: PartialEq<S::Item>, [src]
Self: Sized,
S: Sized + Stream,
Self::Item: PartialEq<S::Item>,
pub fn ge<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>,
pub fn eq<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized + Stream,
S: Sized + Stream,
Self::Item: PartialEq<S::Item>, [src]
Self: Sized + Stream,
S: Sized + Stream,
Self::Item: PartialEq<S::Item>,
pub fn gt<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>,
pub fn le<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>,
pub fn lt<S>(self, other: S) -> ImplFuture<bool> where
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>, [src]
Self: Sized + Stream,
S: Stream,
Self::Item: PartialOrd<S::Item>,
pub fn sum<'a, S>(self) -> ImplFuture<S> where
Self: Sized + Stream<Item = S> + 'a,
S: Sum<Self::Item>, [src]
Self: Sized + Stream<Item = S> + 'a,
S: Sum<Self::Item>,
pub fn product<'a, P>(self) -> ImplFuture<P> where
Self: Sized + Stream<Item = P> + 'a,
P: Product, [src]
Self: Sized + Stream<Item = P> + 'a,
P: Product,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T> where
T: Send,
T: Send,
impl<T> Sync for Receiver<T> where
T: Send,
T: Send,
impl<T> Unpin for Receiver<T>
impl<T> !UnwindSafe for Receiver<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut T)[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,