#event-listener #events #parallel #dispatcher #listener #async

hey_listen

An event-dispatcher-collection offering async, sync, parallel, and prioritised solutions!

8 releases (4 breaking)

0.5.0 Apr 18, 2021
0.4.0 May 5, 2019
0.3.0 May 1, 2019
0.2.1 Dec 6, 2018
0.1.2 Jan 13, 2018

#539 in Concurrency

Download history 48/week @ 2024-07-23 9/week @ 2024-07-30 6/week @ 2024-08-06 11/week @ 2024-08-13 1/week @ 2024-08-20 16/week @ 2024-08-27 10/week @ 2024-09-03 11/week @ 2024-09-10 13/week @ 2024-09-17 46/week @ 2024-09-24 17/week @ 2024-10-01 4/week @ 2024-10-08 12/week @ 2024-10-15 8/week @ 2024-10-22 13/week @ 2024-10-29 16/week @ 2024-11-05

53 downloads per month
Used in danmuji

ISC license

42KB
479 lines

ci-badge docs-badge rust version badge crates.io version

Hey! Listen!

Hey_listen is a collection of event-dispatchers aiming to suit all needs!
Currently covering:

  • Priority dispatch
  • Threadpool dispatch
  • Async dispatch

View the examples-folder on how to use each dispatcher.

Everyone is welcome to contribute, check out the CONTRIBUTING.md for further guidance.

Example

Here is a quick example on how to use the event-dispatcher:

use hey_listen::sync::{
    ParallelDispatcher, ParallelListener, ParallelDispatchResult,
};

#[derive(Clone, Eq, Hash, PartialEq)]
enum Event {
    Variant,
}

struct Listener {}

impl ParallelListener<Event> for Listener {
    fn on_event(&self, _event: &Event) -> Option<ParallelDispatchResult> {
        println!("I'm listening! :)");

        None
    }
}

fn main() {
    let listener = Listener {};
    let mut dispatcher = ParallelDispatcher::<Event>::new(4).expect("Could not construct threadpool");

    dispatcher.add_listener(Event::Variant, listener);
    dispatcher.dispatch_event(&Event::Variant);
}

Installation

Add this to your Cargo.toml:

[dependencies]
hey_listen = "0.5"

Dependencies

~0.4–7.5MB
~66K SLoC