#[cfg(not(feature = "async-trait"))]
use futures::future::BoxFuture;
#[cfg(not(feature = "async-trait"))]
use futures::FutureExt;
use super::FactoryMessage;
use super::JobKey;
use crate::ActorProcessingErr;
use crate::ActorRef;
use crate::Message;
use crate::State;
#[cfg_attr(feature = "async-trait", crate::async_trait)]
pub trait FactoryLifecycleHooks<TKey, TMsg>: State + Sync
where
TKey: JobKey,
TMsg: Message,
{
#[allow(unused_variables)]
#[cfg(feature = "async-trait")]
async fn on_factory_started(
&self,
factory_ref: ActorRef<FactoryMessage<TKey, TMsg>>,
) -> Result<(), ActorProcessingErr> {
Ok(())
}
#[allow(unused_variables)]
#[cfg(not(feature = "async-trait"))]
fn on_factory_started(
&self,
factory_ref: ActorRef<FactoryMessage<TKey, TMsg>>,
) -> BoxFuture<'_, Result<(), ActorProcessingErr>> {
async { Ok(()) }.boxed()
}
#[cfg(feature = "async-trait")]
async fn on_factory_stopped(&self) -> Result<(), ActorProcessingErr> {
Ok(())
}
#[cfg(not(feature = "async-trait"))]
fn on_factory_stopped(&self) -> BoxFuture<'_, Result<(), ActorProcessingErr>> {
async { Ok(()) }.boxed()
}
#[allow(unused_variables)]
#[cfg(feature = "async-trait")]
async fn on_factory_draining(
&self,
factory_ref: ActorRef<FactoryMessage<TKey, TMsg>>,
) -> Result<(), ActorProcessingErr> {
Ok(())
}
#[allow(unused_variables)]
#[cfg(not(feature = "async-trait"))]
fn on_factory_draining(
&self,
factory_ref: ActorRef<FactoryMessage<TKey, TMsg>>,
) -> BoxFuture<'_, Result<(), ActorProcessingErr>> {
async { Ok(()) }.boxed()
}
}