Update random bits and bobs
Signed-off-by: Nikolaos Karaolidis <nick@karaolidis.com>
This commit is contained in:
@@ -26,23 +26,23 @@ pub enum Action {
|
||||
Unsubscribe,
|
||||
}
|
||||
|
||||
impl From<super::Action> for Action {
|
||||
impl From<super::Action> for Option<Action> {
|
||||
fn from(action: super::Action) -> Self {
|
||||
match action {
|
||||
super::Action::Add => Self::Subscribe,
|
||||
super::Action::Remove => Self::Unsubscribe,
|
||||
super::Action::Add | super::Action::Enable => Some(Action::Subscribe),
|
||||
super::Action::Remove | super::Action::Disable => Some(Action::Unsubscribe),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Message {
|
||||
pub action: Action,
|
||||
pub action: Option<Action>,
|
||||
pub symbols: Vec<String>,
|
||||
pub response: oneshot::Sender<()>,
|
||||
}
|
||||
|
||||
impl Message {
|
||||
pub fn new(action: Action, symbols: Vec<String>) -> (Self, oneshot::Receiver<()>) {
|
||||
pub fn new(action: Option<Action>, symbols: Vec<String>) -> (Self, oneshot::Receiver<()>) {
|
||||
let (sender, receiver) = oneshot::channel();
|
||||
(
|
||||
Self {
|
||||
@@ -115,7 +115,7 @@ async fn handle_message(
|
||||
message: Message,
|
||||
) {
|
||||
match message.action {
|
||||
Action::Subscribe => {
|
||||
Some(Action::Subscribe) => {
|
||||
let (pending_subscriptions, receivers): (Vec<_>, Vec<_>) = message
|
||||
.symbols
|
||||
.iter()
|
||||
@@ -144,7 +144,7 @@ async fn handle_message(
|
||||
|
||||
join_all(receivers).await;
|
||||
}
|
||||
Action::Unsubscribe => {
|
||||
Some(Action::Unsubscribe) => {
|
||||
let (pending_unsubscriptions, receivers): (Vec<_>, Vec<_>) = message
|
||||
.symbols
|
||||
.iter()
|
||||
@@ -173,6 +173,7 @@ async fn handle_message(
|
||||
|
||||
join_all(receivers).await;
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
message.response.send(()).unwrap();
|
||||
|
Reference in New Issue
Block a user