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:
Adrian Malacoda
2017-02-25 20:17:46 -06:00
parent 442b617f31
commit 37a9645f5b
11 changed files with 73 additions and 73 deletions

View File

@@ -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![]
}
}
}