routine assigns self reference at construct
This commit is contained in:
parent
2a1a7f8503
commit
6d3b5eee41
1 changed files with 43 additions and 19 deletions
|
@ -645,30 +645,30 @@ pub struct Routine {
|
||||||
impl Routine {
|
impl Routine {
|
||||||
|
|
||||||
|
|
||||||
// pub fn set
|
// // pub fn set
|
||||||
// pub async fn refresh_self_ref(self) {
|
// // pub async fn refresh_self_ref(self) {
|
||||||
pub async fn refresh_routine_internal(routine_ar : RoutineAR)
|
// pub async fn refresh_routine_internal(routine_ar : RoutineAR)
|
||||||
{
|
// {
|
||||||
|
|
||||||
/*
|
// /*
|
||||||
Execute after the Routine is constructed
|
// Execute after the Routine is constructed
|
||||||
- If not, a start() will also call this
|
// - 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;
|
// let mut mut_lock = routine_ar.write().await;
|
||||||
mut_lock.self_routine_ar = Some(routine_ar.clone());
|
// mut_lock.self_routine_ar = Some(routine_ar.clone());
|
||||||
|
|
||||||
// 2. Update the current self_act_ar
|
// // 2. Update the current self_act_ar
|
||||||
mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone()))));
|
// mut_lock.self_act_ar = Some(Arc::new(RwLock::new(BotAction::R(routine_ar.clone()))));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
pub async fn validate_attr(routine_attr : &Vec<RoutineAttr>)
|
pub async fn validate_attr(routine_attr : &Vec<RoutineAttr>)
|
||||||
|
@ -833,8 +833,8 @@ impl Routine {
|
||||||
{
|
{
|
||||||
|
|
||||||
Routine::validate_attr(&routine_attr).await?;
|
Routine::validate_attr(&routine_attr).await?;
|
||||||
|
|
||||||
return Ok(Arc::new(RwLock::new(Routine {
|
let routine_ar = Arc::new(RwLock::new(Routine {
|
||||||
name ,
|
name ,
|
||||||
module ,
|
module ,
|
||||||
channel ,
|
channel ,
|
||||||
|
@ -848,7 +848,31 @@ impl Routine {
|
||||||
internal_signal : RoutineSignal::NotStarted ,
|
internal_signal : RoutineSignal::NotStarted ,
|
||||||
self_routine_ar : None ,
|
self_routine_ar : None ,
|
||||||
self_act_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
|
// // [x] Prep by updating it's own self reference
|
||||||
Routine::refresh_routine_internal(trg_routine_ar.clone()).await;
|
// Routine::refresh_routine_internal(trg_routine_ar.clone()).await;
|
||||||
|
|
||||||
// [x] Asyncio Spawn likely around here
|
// [x] Asyncio Spawn likely around here
|
||||||
// [x] & Assigns self.join_handle
|
// [x] & Assigns self.join_handle
|
||||||
|
|
Loading…
Reference in a new issue