diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 0e6dfc2..49fca78 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -622,7 +622,10 @@ pub struct Routine { exec_body: bot_actions::actions_util::ExecBody, // parent_params : Option , parent_params : ExecBodyParams , - pub join_handle : Option> , + // pub join_handle : Option> , + // pub join_handle : Option> , + // pub join_handle : Option>>> , + pub join_handle : Option>>> , start_time : Option> , complete_iterations : i64 , remaining_iterations : Option , @@ -977,7 +980,7 @@ impl Routine { // let self_ref = Arc::clone(&trg_routine_ar); // trg_routine_ar.write().await.join_handle = innerhelper(trg_routine_ar.clone()).await; { - trg_routine_ar.write().await.join_handle = Some(runonce_innerhelper(trg_routine_ar.clone()).await); + trg_routine_ar.write().await.join_handle = Some(Arc::new(RwLock::new(runonce_innerhelper(trg_routine_ar.clone()).await))); } // if let Some(a) = &trg_routine_ar.read().await.join_handle { diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index 76862f6..1d76930 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -17,6 +17,7 @@ const OF_CMD_CHANNEL:Channel = Channel(String::new()); use casual_logger::Log; use rand::Rng; use tokio::sync::RwLock; +use std::borrow::Borrow; use std::sync::Arc; use crate::core::bot_actions::ExecBodyParams; @@ -88,19 +89,19 @@ async fn test3_body(params : ExecBodyParams) { async fn rtestbody(params : ExecBodyParams) { - let bot = Arc::clone(¶ms.bot); + // let bot = Arc::clone(¶ms.bot); - let botlock = bot.read().await; + // let botlock = bot.read().await; - // uses chat.say_in_reply_to() for the bot controls for messages - botlock - .botmgrs - .chat - .say_in_reply_to( - ¶ms.msg.clone(), - String::from("Inner Routine Loop Message"), - params.clone() - ).await; + // // uses chat.say_in_reply_to() for the bot controls for messages + // botlock + // .botmgrs + // .chat + // .say_in_reply_to( + // ¶ms.msg.clone(), + // String::from("Inner Routine Loop Message"), + // params.clone() + // ).await; let logmsg_botact = match *params.curr_act.read().await { BotAction::C(_) => "command", @@ -115,10 +116,16 @@ async fn test3_body(params : ExecBodyParams) { Some(¶ms.msg), ); Log::flush(); + + for _ in 0..5 { + println!("tester"); + sleep(Duration::from_secs_f64(0.5)).await; + } } + botlog::debug( - format!("TEST3_BODY BEFORE FROM CALL : module - {:?} ; channel - {:?}", + format!("RTESTBODY : module - {:?} ; channel - {:?}", module,channel ).as_str(), Some("experiment003 > test3_body".to_string()), @@ -190,10 +197,20 @@ async fn test3_body(params : ExecBodyParams) { params.clone() ).await; - newr.clone().write().await.join_handle.take().expect("Issue with join handle").await.unwrap(); + // [x] Will not be handling JoinHandles here . If immediate abort() handling is required, below is an example that works + /* - // newr.read().await.join_handle.unwrap().await.unwrap(); + let a = newr.clone().read().await.join_handle.clone(); + match a { + Some(b) => { + b.read().await.borrow().abort(); // [x] <-- This aborts if wanting to abort immediately + //() + }, + None => (), + } + + */ }