pub struct MultiThreadedCallback<T>where
T: Debug,{ /* private fields */ }Expand description
A multithreaded callback holder.
This callback holder will invoke the given events on a separate thread, thus unblocking the caller thread for other tasks.
§Example
use fx_callback::{Callback, MultiThreadedCallback, Subscription};
/// The events of the struct that informs subscribers about changes to the data within the struct.
#[derive(Debug, Clone, PartialEq)]
enum MyEvent {
Foo,
}
/// The struct to which an interested subscriber can subscribe to.
#[derive(Debug)]
struct Example {
callbacks: MultiThreadedCallback<MyEvent>,
}
impl Example {
fn invoke_event(&self) {
self.callbacks.invoke(MyEvent::Foo);
}
}
impl Callback<MyEvent> for Example {
fn subscribe(&self) -> Subscription<MyEvent> {
self.callbacks.subscribe()
}
}Implementations§
Source§impl<T> MultiThreadedCallback<T>
impl<T> MultiThreadedCallback<T>
Sourcepub fn new_with_capacity(capacity: usize) -> Self
pub fn new_with_capacity(capacity: usize) -> Self
Creates a new multithreaded callback with a specified capacity.
Trait Implementations§
Source§impl<T> Callback<T> for MultiThreadedCallback<T>where
T: Debug,
impl<T> Callback<T> for MultiThreadedCallback<T>where
T: Debug,
Source§fn subscribe(&self) -> Subscription<T>
fn subscribe(&self) -> Subscription<T>
Subscribe to the interested event.
This creates a new Subscription that will be invoked with a shared instance of the event when the interested event occurs. Read more
Source§impl<T> Clone for MultiThreadedCallback<T>where
T: Debug,
impl<T> Clone for MultiThreadedCallback<T>where
T: Debug,
Auto Trait Implementations§
impl<T> Freeze for MultiThreadedCallback<T>
impl<T> RefUnwindSafe for MultiThreadedCallback<T>
impl<T> Send for MultiThreadedCallback<T>
impl<T> Sync for MultiThreadedCallback<T>
impl<T> Unpin for MultiThreadedCallback<T>
impl<T> UnsafeUnpin for MultiThreadedCallback<T>
impl<T> UnwindSafe for MultiThreadedCallback<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