Rircd/src/event.rs

48 lines
999 B
Rust

use tokio::sync::oneshot;
use eyre::Result;
pub enum InternalEvent {
Test,
Shutdown,
}
pub enum EventKind {
//TODO maybe make message a trait
Message,
Internal(InternalEvent),
}
//make this an option or create a new type because
//to the receiving endpoint the sender_name is irrelevant
//it only really matters for the routing phase from state::run()
pub struct Event {
pub kind: EventKind,
pub result_sender: oneshot::Sender<EventResponse>,
pub sender_name: String,
}
pub struct EventRaw {
pub kind: EventKind,
pub sender_name: String,
}
pub enum EventResponse {
Success,
SuccessQuery(String),
//use Error type
Failed(String),
}
impl Event {
pub fn new(event_raw: EventRaw) -> (Event,oneshot::Receiver<EventResponse>) {
let (s,r) = oneshot::channel();
(Event {
kind: event_raw.kind,
result_sender: s,
//TODO
sender_name: event_raw.sender_name,
},r)
}
}