From 5434eb9b33c2c4af6750c9c403fb88f9e62a9d37 Mon Sep 17 00:00:00 2001 From: dd di cesare Date: Tue, 1 Oct 2024 18:00:06 +0200 Subject: [PATCH] [refactor] Simplifying Operation state transtion and exec of req msg Signed-off-by: dd di cesare --- src/operation_dispatcher.rs | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) diff --git a/src/operation_dispatcher.rs b/src/operation_dispatcher.rs index 65b9d064..c9c6b0ce 100644 --- a/src/operation_dispatcher.rs +++ b/src/operation_dispatcher.rs @@ -62,28 +62,17 @@ impl Operation { } fn trigger(&self) -> Result { - match self.get_state() { - State::Pending => { - if let Some(message) = - (self.grpc_message_build_fn)(self.get_extension_type(), &self.action) - { - let res = - self.service - .send(self.get_map_values_bytes_fn, self.grpc_call_fn, message); - self.set_result(res); - self.next_state(); - res - } else { - //todo: we need to move to and start the next action - self.done(); - self.get_result() - } - } - State::Waiting => { - self.next_state(); - self.get_result() - } - State::Done => self.get_result(), + if let Some(message) = (self.grpc_message_build_fn)(self.get_extension_type(), &self.action) + { + let res = self + .service + .send(self.get_map_values_bytes_fn, self.grpc_call_fn, message); + self.set_result(res); + self.next_state(); + res + } else { + self.done(); + self.get_result() } } @@ -195,7 +184,7 @@ impl OperationDispatcher { } } State::Waiting => { - let _ = operation.trigger(); + operation.next_state(); Some(operation.clone()) } State::Done => {