From 6d3b5eee41f0600ecacf26440f1313b5fbd8649b Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Thu, 28 Mar 2024 11:50:08 -0400 Subject: [PATCH] routine assigns self reference at construct --- src/core/botmodules.rs | 62 +++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 19 deletions(-) diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 17c570a..8e172f6 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -645,30 +645,30 @@ pub struct Routine { impl Routine { - // pub fn set - // pub async fn refresh_self_ref(self) { - pub async fn refresh_routine_internal(routine_ar : RoutineAR) - { + // // pub fn set + // // pub async fn refresh_self_ref(self) { + // pub async fn refresh_routine_internal(routine_ar : RoutineAR) + // { - /* - Execute after the Routine is constructed - - If not, a start() will also call this + // /* + // Execute after the Routine is constructed + // - If not, a start() will also call this - */ + // */ - // 1. Update the self reference to itself + // // 1. Update the self reference to itself - let mut mut_lock = routine_ar.write().await; - mut_lock.self_routine_ar = Some(routine_ar.clone()); + // let mut mut_lock = routine_ar.write().await; + // mut_lock.self_routine_ar = Some(routine_ar.clone()); - // 2. Update the current self_act_ar - mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone())))); + // // 2. Update the current self_act_ar + // mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone())))); - } + // } pub async fn validate_attr(routine_attr : &Vec) @@ -833,8 +833,8 @@ impl Routine { { Routine::validate_attr(&routine_attr).await?; - - return Ok(Arc::new(RwLock::new(Routine { + + let routine_ar = Arc::new(RwLock::new(Routine { name , module , channel , @@ -848,7 +848,31 @@ impl Routine { internal_signal : RoutineSignal::NotStarted , self_routine_ar : None , self_act_ar : None , - }))) ; + })); + + let mut mut_lock = routine_ar.write().await; + mut_lock.self_routine_ar = Some(routine_ar.clone()); + + // 2. Update the current self_act_ar + mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone())))); + + Ok(routine_ar.clone()) + + // return Ok(Arc::new(RwLock::new(Routine { + // name , + // module , + // channel , + // exec_body , + // parent_params , + // join_handle : None , + // start_time : None , + // complete_iterations : 0 , + // remaining_iterations : None , + // routine_attr : routine_attr , + // internal_signal : RoutineSignal::NotStarted , + // self_routine_ar : None , + // self_act_ar : None , + // }))) ; } @@ -861,8 +885,8 @@ impl Routine { { - // [x] Prep by updating it's own self reference - Routine::refresh_routine_internal(trg_routine_ar.clone()).await; + // // [x] Prep by updating it's own self reference + // Routine::refresh_routine_internal(trg_routine_ar.clone()).await; // [x] Asyncio Spawn likely around here // [x] & Assigns self.join_handle