Async event system

avent - An async event system, which uses tokio broadcast. It would be interesting to know, if there is a way to get rid of the mutex used in the linked file, or maybe a better idea how to build this system in general.
The dev branch in the repository holds the latest state and test usage can be seen under: example
Thanks in advance!

As far as I can see, you are managing resources for your users. It may be better to push that responsibility on the user, which would give them more control by changing

pub trait Recv : 'static + std::marker::Send {
    type EventType;
    type ContextType;

    fn handle(&self, event: Self::EventType, context: &mut Self::ContextType) -> impl std::future::Future<Output = ()> + Send;
}

to

pub trait Recv : 'static + std::marker::Send {
    type EventType;
    type ContextType;

    fn handle(&self, event: Self::EventType, context: &Self::ContextType) -> impl std::future::Future<Output = ()> + Send;
}

You can also drop Send bound from ContextType.

Users can use Mutex themselfs or some other Sync context type, like channel or AtomicUsize

1 Like

Thanks for responding, that makes sense I guess and should simplify the code :slight_smile:

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.