Skip to content
This repository has been archived by the owner on Oct 23, 2022. It is now read-only.

Latest commit

 

History

History
42 lines (36 loc) · 797 Bytes

README.md

File metadata and controls

42 lines (36 loc) · 797 Bytes

netrex_events

A unconvential way to handle events with rust

API:

#[derive(Clone)]
enum Event {
    HelloWorld,
    GoodbyeWorld,
}

#[derive(Debug, Clone)]
enum EventResult {
    Complete,
    Incomplete,
}

let channel = Channel::<Event, EventResult>::new();
let mut some_value = 0;

// Our listener
let mut listener = |event, _current| {
    match event {
        Event::HelloWorld => {
            some_value += 1;
            if some_value == 3 {
                return Some(EventResult::Incomplete);
            }
            Some(EventResult::Complete)
        }
        Event::GoodbyeWorld => Some(EventResult::Incomplete),
    }
};

channel.receive(&mut listener);

// lets emit 12 times
for _ in 0..12 {
    let result = channel.send(Event::HelloWorld);
    dbg!(result);
}