Skip to content
This repository was archived by the owner on Oct 23, 2022. It is now read-only.
/ Events Public archive

A unconvential way to handle events with rust.

Notifications You must be signed in to change notification settings

NetrexMC/Events

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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);
}

About

A unconvential way to handle events with rust.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages