#events #emitter #publish #subscribe #pub-sub #ee

alone_ee

Small event emitter for rapid development of weak dependency in applications. simple. powerful. predicted

26 stable releases

1.7.3 May 1, 2020
1.7.0 Jan 21, 2020
1.4.2 Dec 15, 2019
1.1.0 Nov 19, 2019
1.0.3 Oct 29, 2019

#1220 in Rust patterns

Download history 9/week @ 2024-04-01

71 downloads per month

GPL-3.0 license

12KB
254 lines

alone_ee

The simplest event emitter for rust

fn main () { 
    use alone_ee::event_emitter::EventEmitter;
    let ee = EventEmitte::Stringr::new();

    let subscription1 = ee.on(Box::new(|event_data| {  // listener will be alive till subscription is alive 
        // do something
        println!("hello {}", event_data);
        Ok(())
    }));

    let _subscription2 = ee.once(Box::new(|event_data| {   // listener will be alive till subscription is alive or next emit will fired
        // do something
        println!("hello {} one more time", event_data);
        Ok(())
    }));

    ee.emit("world1").unwrap();
    ee.emit("world2").unwrap();

    // you will see 
    //     "hello world1"
    //     "hello world1 one more time"
    //     "hello world2"

    drop(subscription1); // unbind the listener
    // _subscription2 will be removed automatically
}

Testing

$ cargo test --release

Benchmark

$ cargo bench

Dependencies

~110KB