pub struct MultiThreadedCallback<T>{ /* 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, Subscriber, 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()
}
fn subscribe_with(&self, subscriber: Subscriber<MyEvent>) {
self.callbacks.subscribe_with(subscriber)
}
}
Implementations§
Source§impl<T> MultiThreadedCallback<T>
impl<T> MultiThreadedCallback<T>
Trait Implementations§
Source§impl<T> Callback<T> for MultiThreadedCallback<T>
impl<T> Callback<T> for MultiThreadedCallback<T>
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§fn subscribe_with(&self, subscriber: Subscriber<T>)
fn subscribe_with(&self, subscriber: Subscriber<T>)
Subscribe to the interested event with a Subscriber.
This creates an underlying new subscription which will be invoked with the given subscriber when the interested event occurs. Read more
Source§impl<T> Clone for MultiThreadedCallback<T>
impl<T> Clone for MultiThreadedCallback<T>
Source§fn clone(&self) -> MultiThreadedCallback<T>
fn clone(&self) -> MultiThreadedCallback<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto 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> 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