Struct unbounded_spsc::Receiver
source · pub struct Receiver<T> { /* private fields */ }
Implementations§
source§impl<T> Receiver<T>
impl<T> Receiver<T>
sourcepub fn try_recv(&self) -> Result<T, TryRecvError>
pub fn try_recv(&self) -> Result<T, TryRecvError>
Non-blocking receive, returns Err (TryRecvError::Empty)
if buffer was
empty; will continue to receive pending messages from a disconnected
channel until it is empty, at which point further calls to this function
will return Err (TryRecvError::Disconnected)
.
Examples found in repository?
examples/sequential-try_recv.rs (line 33)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
let start_time = std::time::SystemTime::now();
loop {
match receiver.try_recv() {
Ok (_m) => (),
Err (unbounded_spsc::TryRecvError::Empty) => (),
Err (unbounded_spsc::TryRecvError::Disconnected) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
examples/parallel-try_recv.rs (line 44)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until sender is started
while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
loop {
match receiver.try_recv() {
Ok (_m) => (),
Err (unbounded_spsc::TryRecvError::Empty) => (),
Err (unbounded_spsc::TryRecvError::Disconnected) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
sourcepub fn recv(&self) -> Result<T, RecvError>
pub fn recv(&self) -> Result<T, RecvError>
Block waiting if no messages are pending in the buffer.
Examples found in repository?
examples/sequential-recv.rs (line 33)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
let start_time = std::time::SystemTime::now();
loop {
match receiver.recv() {
Ok (_m) => (),
Err (_e) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
examples/parallel-recv.rs (line 44)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until sender is started
while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
loop {
match receiver.recv() {
Ok (_m) => (),
Err (_e) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
pub fn recv_timeout(&self, timeout: Duration) -> Result<T, RecvTimeoutError>
pub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn try_iter(&self) -> TryIter<'_, T> ⓘ
sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Examples found in repository?
examples/sequential-recv.rs (line 43)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
let start_time = std::time::SystemTime::now();
loop {
match receiver.recv() {
Ok (_m) => (),
Err (_e) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
More examples
examples/sequential-try_recv.rs (line 44)
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
let start_time = std::time::SystemTime::now();
loop {
match receiver.try_recv() {
Ok (_m) => (),
Err (unbounded_spsc::TryRecvError::Empty) => (),
Err (unbounded_spsc::TryRecvError::Disconnected) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
examples/parallel-recv.rs (line 54)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until sender is started
while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
loop {
match receiver.recv() {
Ok (_m) => (),
Err (_e) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
examples/parallel-try_recv.rs (line 55)
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn recvfun (receiver : unbounded_spsc::Receiver <Mystruct>) {
RECEIVER_STARTED.store (true, std::sync::atomic::Ordering::SeqCst);
// spin until sender is started
while !SENDER_STARTED.load (std::sync::atomic::Ordering::SeqCst) {}
let start_time = std::time::SystemTime::now();
loop {
match receiver.try_recv() {
Ok (_m) => (),
Err (unbounded_spsc::TryRecvError::Empty) => (),
Err (unbounded_spsc::TryRecvError::Disconnected) => break
}
}
let duration = start_time.elapsed().unwrap();
let duration_ns
= (duration.as_secs() * 1_000_000_000) + duration.subsec_nanos() as u64;
println!("recvfun duration ns: {}", duration_ns);
println!("recvfun ns per message: {}", duration_ns / MESSAGE_COUNT);
println!("buffer ending capacity: {}", receiver.capacity());
}
pub fn can_recv(&self) -> bool
pub fn start_selection(&self, token: SignalToken) -> SelectionResult
Trait Implementations§
source§impl<'a, T> IntoIterator for &'a Receiver<T>
impl<'a, T> IntoIterator for &'a Receiver<T>
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Receiver<T>
impl<T> Send for Receiver<T>where T: Send,
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