pub struct Receiver<T> { /* private fields */ }
Expand description
Implementations§
Source§impl<T> Receiver<T>
impl<T> Receiver<T>
Sourcepub fn borrow(&self) -> Ref<'_, T>
pub fn borrow(&self) -> Ref<'_, T>
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_watch2::channel("hello");
assert_eq!(*rx.borrow(), "hello");
Source§impl<T: Clone> Receiver<T>
impl<T: Clone> Receiver<T>
Sourcepub async fn recv(&mut self) -> Option<T>
pub async fn recv(&mut self) -> Option<T>
Attempts to clone the latest value sent via the channel.
If this is the first time the function is called on a Receiver
instance, then the function completes immediately with the current
value held by the channel. On the next call, the function waits until
a new value is sent in the channel.
None
is returned if the Sender
half is dropped.
§Examples
let (tx, mut rx) = async_watch2::channel("hello");
let v = rx.recv().await.unwrap();
assert_eq!(v, "hello");
let task = executor.spawn(async move {
tx.broadcast("goodbye").unwrap();
});
// 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_none());
task.await;
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for Receiver<T>
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>
impl<T> Sync for Receiver<T>
impl<T> Unpin for Receiver<T>
impl<T> !UnwindSafe for Receiver<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more