[−][src]Struct async_watch::Receiver
Implementations
impl<T> Receiver<T>
[src]
pub fn borrow(&self) -> Ref<'_, T>
[src]
Returns a reference to the most recently sent value.
Outstanding borrows hold a read lock. This means that long lived borrows could cause the send half to block. It is recommended to keep the borrow as short lived as possible.
Examples
let (_, rx) = async_watch::channel("hello"); assert_eq!(*rx.borrow(), "hello");
pub async fn changed<'_>(&'_ mut self) -> Result<(), RecvError>
[src]
Wait for a change notification.
Returns when a new value has been sent by the Sender
since the last
time changed()
was called. When the Sender
half is dropped, Err
is
returned.
Examples
let (tx, mut rx) = async_watch::channel("hello"); let task = executor.spawn(async move { tx.send("goodbye").unwrap(); }); assert!(rx.changed().await.is_ok()); assert_eq!(*rx.borrow(), "goodbye"); // The `tx` handle has been dropped assert!(rx.changed().await.is_err()); task.await; });
impl<T: Clone> Receiver<T>
[src]
pub async fn recv<'_>(&'_ mut self) -> Result<T, RecvError>
[src]
A convenience helper which combines calling Receiver::changed()
and
Receiver::borrow()
where the borrowed value is cloned and returned.
Note: If this is the first time the function is called on a Receiver
instance, then the function will wait until a new value is sent into the channel.
None
is returned if the Sender
half is dropped.
Examples
let (tx, mut rx) = async_watch::channel("hello"); let task = executor.spawn(async move { tx.send("goodbye").unwrap(); }); assert_eq!(*rx.borrow(), "hello"); // Waits for the new task to spawn and send the value. let v = rx.recv().await.unwrap(); assert_eq!(v, "goodbye"); let v = rx.recv().await; assert!(v.is_err()); task.await;
Trait Implementations
impl<T> Clone for Receiver<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Receiver<T>
[src]
impl<T> Drop for Receiver<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T> where
T: Send + Sync,
T: Send + Sync,
impl<T> Sync for Receiver<T> where
T: Send + Sync,
T: Send + Sync,
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,
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.
fn to_owned(&self) -> T
[src]
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.
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>,