[−][src]Struct multiqueue2::BroadcastSender
This class is the sending half of the broadcasting MultiQueue
. It supports both
single and multi consumer modes with competitive performance in each case.
It only supports nonblocking writes (the futures sender being an exception)
as well as being the conduit for adding new writers.
Examples
use std::thread; let (send, recv) = multiqueue2::broadcast_queue(4); let mut handles = vec![]; for i in 0..2 { // or n let cur_recv = recv.add_stream(); for j in 0..2 { let stream_consumer = cur_recv.clone(); handles.push(thread::spawn(move || { for val in stream_consumer { println!("Stream {} consumer {} got {}", i, j, val); } })); } // cur_recv is dropped here } // Take notice that I drop the reader - this removes it from // the queue, meaning that the readers in the new threads // won't get starved by the lack of progress from recv recv.unsubscribe(); for i in 0..10 { // Don't do this busy loop in real stuff unless you're really sure loop { if send.try_send(i).is_ok() { break; } } } drop(send); for t in handles { t.join(); } // prints along the lines of // Stream 0 consumer 1 got 2 // Stream 0 consumer 0 got 0 // Stream 1 consumer 0 got 0 // Stream 0 consumer 1 got 1 // Stream 1 consumer 1 got 1 // Stream 1 consumer 0 got 2 // etc
Implementations
impl<T: Clone> BroadcastSender<T>
[src]
pub fn try_send(&self, val: T) -> Result<(), TrySendError<T>>
[src]
pub fn unsubscribe(self)
[src]
Removes the writer from the queue
Trait Implementations
impl<T: Clone> Clone for BroadcastSender<T>
[src]
pub fn clone(&self) -> BroadcastSender<T>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Send + Sync + Clone> Send for BroadcastSender<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for BroadcastSender<T>
[src]
impl<T> !Sync for BroadcastSender<T>
[src]
impl<T> Unpin for BroadcastSender<T>
[src]
impl<T> !UnwindSafe for BroadcastSender<T>
[src]
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,
pub 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> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,