routine assigns self reference at construct

This commit is contained in:
ModulatingForce 2024-03-28 11:50:08 -04:00
parent 2a1a7f8503
commit 6d3b5eee41

View file

@ -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<RoutineAttr>)
@ -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