pub struct UReceiver<T> { /* private fields */ }Expand description
The receiving side of the unbounded queue.
§Examples
use std::thread;
use std::time::Duration;
use omango::queue::spsc::unbounded;
let (tx, rx) = unbounded();
thread::spawn(move || {
let _ = tx.send(1);
thread::sleep(Duration::from_secs(1));
let _ = tx.send(2);
});
assert_eq!(rx.recv(), Ok(1)); // Received immediately.
assert_eq!(rx.recv(), Ok(2)); // Received after 1 second.Implementations§
Source§impl<T: Send> UReceiver<T>
impl<T: Send> UReceiver<T>
Sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Blocks the current thread until a message is received.
When the queue was closed, all receiving waiters will be woken up and return error.
§Examples
use std::thread;
use std::time::Duration;
use omango::queue::spsc::unbounded;
use omango::error::RecvError;
let (tx, rx) = unbounded();
thread::spawn(move || {
thread::sleep(Duration::from_secs(1));
tx.send(5).unwrap();
thread::sleep(Duration::from_secs(1));
tx.close();
});
assert_eq!(rx.recv(), Ok(5));
assert_eq!(rx.recv(), Err(RecvError));Sourcepub fn close(&self)
pub fn close(&self)
Fires closing queue notification.
After closed, all send operations will be failed.
Uses recv to read remaining messages.
§Examples
use std::thread;
use std::time::Duration;
use omango::queue::spsc::unbounded;
use omango::error::{RecvError, SendError};
let (tx, rx) = unbounded();
thread::spawn(move || {
assert_eq!(tx.send(1), Ok(()));
tx.close();
});
thread::sleep(Duration::from_millis(500));
assert_eq!(rx.recv(), Ok(1));Trait Implementations§
impl<T: Send> Send for UReceiver<T>
impl<T: Send> Sync for UReceiver<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for UReceiver<T>
impl<T> !UnwindSafe for UReceiver<T>
impl<T> Freeze for UReceiver<T>
impl<T> Unpin for UReceiver<T>
impl<T> UnsafeUnpin for UReceiver<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