pub(crate) mod thread_executor;
use crate::actor::ActorCell;
use crate::config::ExecutorType;
use crate::system::RuntimeManagerRef;
use crate::util::CommandChannel;
pub enum ExecutorCommands {
AssignActor(ActorCell),
Shutdown,
}
pub trait ExecutorFactory {
fn spawn_executor(
&self,
name: String,
command_channel: CommandChannel<ExecutorCommands>,
manager_ref: RuntimeManagerRef,
) -> ExecutorHandle;
}
pub trait Executor {
fn run(self);
}
pub struct ExecutorHandle {
close_fn: Box<dyn FnOnce()>,
}
impl ExecutorHandle {
pub fn new<F: FnOnce() + 'static>(close_fn: F) -> ExecutorHandle {
ExecutorHandle {
close_fn: Box::new(close_fn),
}
}
pub(crate) fn await_close(self) {
(self.close_fn)();
}
}
pub fn get_executor_factory(executor_type: &ExecutorType) -> Box<dyn ExecutorFactory> {
match executor_type {
ExecutorType::Thread => Box::new(thread_executor::ThreadExecutorFactory {}),
}
}