pub struct Receiver<T, const N: usize> { /* private fields */ }
Expand description
Receiver half of the queue.
Implementations§
Source§impl<T, const N: usize> Receiver<T, N>
impl<T, const N: usize> Receiver<T, N>
Sourcepub fn try_recv(&mut self) -> Result<Item<T>, Option<Instant>>
pub fn try_recv(&mut self) -> Result<Item<T>, Option<Instant>>
Tries to receive from the queue without blocking. Immediate items are returned first, then scheduled items in the order of earliest deadline first. Error contains an optional Instant of the earliest (not ready) deadline in the queue.
Sourcepub fn recv(&mut self) -> Item<T>
pub fn recv(&mut self) -> Item<T>
Tries to receive from the queue and blocks the current thread if queue is empty. Immediate items are returned first, then scheduled items in the order of earliest deadline first.
Examples found in repository?
examples/simple.rs (line 12)
7fn main() {
8 let (tx, mut rx) = FutexQueue::<u32, 4>::new();
9 let now = Instant::now();
10
11 let thread = thread::spawn(move || loop {
12 let item = rx.recv();
13 println!(
14 "{} ms: Received: {}",
15 now.elapsed().as_millis(),
16 item.value()
17 );
18 });
19
20 tx.send(1).unwrap();
21 tx.send_scheduled(2, now + Duration::from_secs(1)).unwrap();
22 tx.send(3).unwrap();
23 tx.send_scheduled(4, now + Duration::from_secs(2)).unwrap();
24
25 thread.join().unwrap();
26}
Auto Trait Implementations§
impl<T, const N: usize> Freeze for Receiver<T, N>
impl<T, const N: usize> RefUnwindSafe for Receiver<T, N>
impl<T, const N: usize> Send for Receiver<T, N>where
T: Send,
impl<T, const N: usize> Sync for Receiver<T, N>where
T: Send,
impl<T, const N: usize> Unpin for Receiver<T, N>
impl<T, const N: usize> UnwindSafe for Receiver<T, N>
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