diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-12-10 16:47:56 +0100 |
---|---|---|
committer | Matthias Beyer <mail@beyermatthias.de> | 2021-12-10 16:47:56 +0100 |
commit | ea0f2c399320b7bf0f51ada34451bc21100dbafa (patch) | |
tree | 6219616956d6000b8ebf0cfe8546ae5147f60251 | |
parent | 57a595b521a43da2c61c44fd6257477a1a141eb8 (diff) |
Add types for controlling a reactor implementation
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r-- | lib/src/reactor/ctrl.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/src/reactor/ctrl.rs b/lib/src/reactor/ctrl.rs new file mode 100644 index 0000000..92246a9 --- /dev/null +++ b/lib/src/reactor/ctrl.rs @@ -0,0 +1,36 @@ +use std::fmt::Debug; + +use tokio::sync::mpsc::UnboundedSender as Sender; +use tokio::sync::mpsc::UnboundedReceiver as Receiver; + +/// Type for sending messages to a reactor +pub type ReactorSender<CustomRequest, CustomReply> = Sender<(ReactorRequest<CustomRequest>, ReplyChannel<CustomReply>)>; + +/// Type that is used by a reactor for receiving messages +pub type ReactorReceiver<CustomRequest, CustomReply> = Receiver<(ReactorRequest<CustomRequest>, ReplyChannel<CustomReply>)>; + +/// Type that represents the channel that has to be send with a request to a reactor for getting an +/// answer back +pub type ReplyChannel<CustomReply> = Sender<ReactorReply<CustomReply>>; + +pub type ReplyReceiver<CustomReply> = Receiver<ReactorReply<CustomReply>>; + +/// Send control messages to the reactor +#[derive(Debug)] +pub enum ReactorRequest<CustomRequest: Debug + Send + Sync> { + /// check if the reactor still responds + Ping, + + /// Quit the reactor + Exit, + + Custom(CustomRequest), +} + +#[derive(Debug)] +pub enum ReactorReply<CustomReply: Debug + Send + Sync> { + Pong, + Exiting, + + Custom(CustomReply), +} |