Simplify module trait by combining produce/consume event methods into a single run method that runs in the module's own thread and can produce and/or consume events. Introduce an Envelope struct that encapsulates event + to/from so we can (eventually) tag every event and also limit where events are sent (e.g. you can have a specific module configured to talk or listen only to a certain other module).
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use {Message, Channel, User};
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
pub enum Event {
|
||||
Message { message: Message }, // A user sends a message
|
||||
|
||||
@@ -9,3 +11,19 @@ pub enum Event {
|
||||
UserJoin { channel: Channel, user: User }, // A user joins a channel
|
||||
UserQuit { channel: Channel, user: User } // A user quits a channel
|
||||
}
|
||||
|
||||
pub struct Envelope {
|
||||
pub from: Option<String>,
|
||||
pub event: Arc<Event>,
|
||||
pub to: Vec<String>
|
||||
}
|
||||
|
||||
impl Envelope {
|
||||
pub fn new (event: Event) -> Envelope {
|
||||
Envelope {
|
||||
from: None,
|
||||
event: Arc::new(event),
|
||||
to: vec![]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user