proper join handling at custom
All checks were successful
ci/woodpecker/pr/cargo-checks Pipeline was successful

This commit is contained in:
ModulatingForce 2024-03-27 14:51:56 -04:00
parent b08d91af5d
commit 8da8460e47
2 changed files with 36 additions and 16 deletions

View file

@ -622,7 +622,10 @@ pub struct Routine {
exec_body: bot_actions::actions_util::ExecBody,
// parent_params : Option<ExecBodyParams> ,
parent_params : ExecBodyParams ,
pub join_handle : Option<JoinHandle<()>> ,
// pub join_handle : Option<JoinHandle<()>> ,
// pub join_handle : Option<JoinHandle<()>> ,
// pub join_handle : Option<Arc<RwLock<JoinHandle<()>>>> ,
pub join_handle : Option<Arc<RwLock<JoinHandle<()>>>> ,
start_time : Option<DateTime<Local>> ,
complete_iterations : i64 ,
remaining_iterations : Option<i64> ,
@ -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 {

View file

@ -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(&params.bot);
// let bot = Arc::clone(&params.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(
&params.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(
// &params.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(&params.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 => (),
}
*/
}