Struct parallel_event_emitter::ParallelEventEmitter
[−]
[src]
pub struct ParallelEventEmitter<K: EventKey = String> { /* fields omitted */ }
Parallel Event Emitter
Listeners added to the emitter will be invoked in a thread pool concurrently.
Methods
impl<K: EventKey> ParallelEventEmitter<K>[src]
fn new() -> ParallelEventEmitter<K>
Creates a new ParallelEventEmitter with the default CpuPool
fn with_pool(pool: CpuPool) -> ParallelEventEmitter<K>
Creates a new ParallelEventEmitter with an already existing CpuPool instance.
This allows for custom thread preferences and lifecycle hooks.
fn event_names(&self) -> EventResult<Vec<K>>
Collect the names of all events being listened for.
Unfortunately, this method locks a mutex on an internal structure, so an iterator cannot be returned.
fn event_names_visitor<F>(&self, visitor: F) -> EventResult<()> where F: Fn(&K)
As an alternative to cloning all the event names and collecting them into a Vec,
like in event_names,
a visitor callback can be used to iterate all the event names more efficiently.
fn add_listener<F, E: Into<K>>(&mut self,
event: E,
cb: F)
-> EventResult<ListenerId> where F: Fn() -> EventResult<()> + 'static
event: E,
cb: F)
-> EventResult<ListenerId> where F: Fn() -> EventResult<()> + 'static
Add a simple listener callback that does not accept any arguments
The return value of this is a unique ID for that listener, which can later be used to remove it if desired.
fn once<F, E: Into<K>>(&mut self, event: E, cb: F) -> EventResult<ListenerId> where F: Fn() -> EventResult<()> + 'static
Like add_listener, but the listener will be removed from the event emitter after a single invocation.
fn add_listener_value<T, F, E: Into<K>>(&mut self,
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Clone + Send, F: Fn(Option<T>) -> EventResult<()> + 'static
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Clone + Send, F: Fn(Option<T>) -> EventResult<()> + 'static
Add a listener that can accept a value passed via emit_value, or emit_value_sync if T is Clone
If no value or an incompatible value was passed to emit*, None is passed.
The return value of this is a unique ID for that listener, which can later be used to remove it if desired.
fn once_value<T, F, E: Into<K>>(&mut self,
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Clone + Send, F: Fn(Option<T>) -> EventResult<()> + 'static
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Clone + Send, F: Fn(Option<T>) -> EventResult<()> + 'static
Like add_listener_value, but the listener will be removed from the event emitter after a single invocation.
fn add_listener_sync<T, F, E: Into<K>>(&mut self,
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Send + Sync, F: Fn(Option<&T>) -> EventResult<()> + 'static
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Send + Sync, F: Fn(Option<&T>) -> EventResult<()> + 'static
Variation of add_listener_value that accepts Sync types,
where intermediate copies on emit* are unnecessary.
This will attempt to use a reference to the original
value passed to emit_value_sync. If a value of T was passed via emit_value,
the callback will be invoked with the Cloned copy.
There is nothing statically forcing the use of this instead of add_listener_value,
but it is here just in case your type T is Sync but might not implement Clone,
or if you want to avoid cloning values all over the place.
The return value of this is a unique ID for that listener, which can later be used to remove it if desired.
fn once_sync<T, F, E: Into<K>>(&mut self,
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Send + Sync, F: Fn(Option<&T>) -> EventResult<()> + 'static
event: E,
cb: F)
-> EventResult<ListenerId> where T: Any + Send + Sync, F: Fn(Option<&T>) -> EventResult<()> + 'static
Like add_listener_sync, but the listener will be removed from the event emitter after a single invocation.
fn remove_listener<E: Into<K>>(&mut self,
event: E,
id: ListenerId)
-> EventResult<bool>
event: E,
id: ListenerId)
-> EventResult<bool>
Removes a listener with the given ID and associated with the given event.
If the listener was not found (either doesn't exist or the wrong event given) Ok(false) is returned.
If the listener was removed, Ok(true) is returned.
fn remove_any_listener(&mut self, id: ListenerId) -> EventResult<bool>
Exhaustively searches through ALL events for a listener with the given ID.
Ok(false) is returned if it was not found.
fn emit<E: Into<K>>(&mut self, event: E) -> BoxFuture<usize, Trace<EventError>>
Emit an event, invoking all the listeners for that event in the thread pool concurrently.
The Future returned by emit resolves to the number of listeners invoked,
and any errors should be forwarded up.
fn emit_value<T, E: Into<K>>(&mut self,
event: E,
value: T)
-> BoxFuture<usize, Trace<EventError>> where T: Any + Clone + Send
event: E,
value: T)
-> BoxFuture<usize, Trace<EventError>> where T: Any + Clone + Send
Emit an event, invoking all the listeners for that event in the thread pool concurrently.
A copy of the value will be passed to every listener.
The Future returned by emit_value resolves to the number of listeners invoked,
and any errors should be forwarded up.
fn emit_value_sync<T, E: Into<K>>(&mut self,
event: E,
value: T)
-> BoxFuture<usize, Trace<EventError>> where T: Any + Send + Sync
event: E,
value: T)
-> BoxFuture<usize, Trace<EventError>> where T: Any + Send + Sync
Variation of emit_value for Sync types, where intermediate copies are unnecessary.
All listeners receive a reference to the same value.
The Future returned by emit_value_sync resolves to the number of listeners invoked,
and any errors should be forwarded up.
Trait Implementations
impl<K: EventKey> Default for ParallelEventEmitter<K>[src]
fn default() -> ParallelEventEmitter<K>
Returns the "default value" for a type. Read more