#[macro_export]
macro_rules! impl_mac_task_actor
{
($actor_type:ident) =>
{
paste!
{
pub struct $actor_type
{
}
impl $actor_type
{
pub fn spawn(state: [<$actor_type State>], ex: &Executor)
{
let task = ex.spawn(async move {
$actor_type::run(state).await;
});
task.detach();
}
pub fn spawn_attached(state: [<$actor_type State>], ex: &Executor) -> Task<()>
{
ex.spawn(async move {
$actor_type::run(state).await;
})
}
async fn run(mut state: [<$actor_type State>])
{
let mut proceed = true;
if state.pre_run_async().await
{
while proceed
{
proceed = state.run_async().await;
}
}
state.post_run_async().await;
}
}
}
}
}
#[macro_export]
macro_rules! impl_mac_task_actor_built_state
{
($actor_type:ident) =>
{
paste!
{
pub struct $actor_type
{
}
impl $actor_type
{
pub fn spawn(state_builder: [<$actor_type StateBuilder>], ex: &Executor)
{
let task = ex.spawn(async move {
$actor_type::run(state_builder).await;
});
task.detach();
}
pub fn spawn_attached(state_builder: [<$actor_type StateBuilder>], ex: &Executor) -> Task<()>
{
let task = ex.spawn(async move {
$actor_type::run(state_builder).await;
})
}
async fn run(mut state_builder: [<$actor_type StateBuilder>])
{
let mut opt_state = state_builder.build_async().await;
if let Some(mut state) = opt_state
{
let mut proceed = true;
if state.pre_run_async().await
{
while proceed
{
proceed = state.run_async().await;
}
}
state.post_run_async().await;
}
}
}
}
}
}