use std::any::Any;
use std::sync::Arc;
use super::{AnyRunnable, Resolve, Runnable};
pub struct RunnableInstance<S> {
pub(crate) name: Arc<str>,
pub(crate) identity: Arc<dyn Any + Send + Sync>,
pub(crate) runnable: Arc<dyn AnyRunnable<S>>,
}
impl<S> Clone for RunnableInstance<S> {
fn clone(&self) -> Self {
Self {
name: self.name.clone(),
identity: self.identity.clone(),
runnable: self.runnable.clone(),
}
}
}
impl<S: Send + Sync + 'static> RunnableInstance<S> {
pub fn new<D: Resolve<S>>(
name: impl Into<Arc<str>>,
runnable: Arc<dyn Runnable<S, D>>,
) -> Self {
let name = name.into();
let identity: Arc<dyn Any + Send + Sync> = runnable.clone();
Self {
runnable: super::erased::erase_runnable(name.clone(), runnable),
name,
identity,
}
}
pub fn name(&self) -> &str {
&self.name
}
}