Add callback exeucutor - part 2
+use std::future::Future;
use std::rc::Rc;
use tornado_common_api::Action;
use crate::{ExecutorError, StatefulExecutor, StatelessExecutor};
-pub struct CallbackStatefulExecutor<F: FnMut(Rc<Action>) -> Result<(), ExecutorError>>{
+pub struct CallbackStatefulExecutor<F: FnMut(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>>{
callback: F
}
-impl <F: FnMut(Rc<Action>) -> Result<(), ExecutorError>> CallbackStatefulExecutor<F> {
+impl <F: FnMut(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>> CallbackStatefulExecutor<F, Fut> {
pub fn new(callback: F) -> Self {
Self {
callback
@@ -15,18 +16,18 @@ impl <F: FnMut(Rc<Action>) -> Result<(), ExecutorError>> CallbackStatefulExecuto
}
#[async_trait::async_trait(?Send)]
-impl <F: FnMut(Rc<Action>) -> Result<(), ExecutorError>> StatefulExecutor for CallbackStatefulExecutor<F> {
+impl <F: FnMut(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>> StatefulExecutor for CallbackStatefulExecutor<F, Fut> {
async fn execute(&mut self, action: Rc<Action>) -> Result<(), ExecutorError> {
- unimplemented!()
+ (self.callback)(action).await
}
}
-pub struct CallbackStatelessExecutor<F: Fn(Rc<Action>) -> Result<(), ExecutorError>>{
+pub struct CallbackStatelessExecutor<F: Fn(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>>{
callback: F
}
-impl <F: Fn(Rc<Action>) -> Result<(), ExecutorError>> CallbackStatelessExecutor<F> {
+impl <F: Fn(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>> CallbackStatelessExecutor<F, Fut> {
pub fn new(callback: F) -> Self {
Self {
callback
@@ -35,9 +36,9 @@ impl <F: Fn(Rc<Action>) -> Result<(), ExecutorError>> CallbackStatelessExecutor<
}
#[async_trait::async_trait(?Send)]
-impl <F: Fn(Rc<Action>) -> Result<(), ExecutorError>> StatelessExecutor for CallbackStatelessExecutor<F> {
+impl <F: Fn(Rc<Action>) -> Fut, Fut: Future<Output = Result<(), ExecutorError>>> StatelessExecutor for CallbackStatelessExecutor<F, Fut> {
async fn execute(&self, action: Rc<Action>) -> Result<(), ExecutorError> {
- unimplemented!()
+ (self.callback)(action).await
}
}
\ No newline at end of file
