experiment routinelike tokio spawn
This commit is contained in:
parent
46ecc15b67
commit
9b7650053e
1 changed files with 45 additions and 0 deletions
|
@ -89,6 +89,25 @@ pub async fn init(mgr: Arc<ModulesManager>) {
|
||||||
// 2. Add the BotAction to ModulesManager
|
// 2. Add the BotAction to ModulesManager
|
||||||
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// 1. Define the BotAction
|
||||||
|
let botc1 = BotCommand {
|
||||||
|
module: BotModule(String::from("experiments001")),
|
||||||
|
command: String::from("rtest"), // command call name
|
||||||
|
alias: vec![], // String of alternative names
|
||||||
|
exec_body: actions_util::asyncbox(routinelike),
|
||||||
|
help: String::from("routinelike"),
|
||||||
|
required_roles: vec![
|
||||||
|
BotAdmin,
|
||||||
|
// Mod(OF_CMD_CHANNEL),
|
||||||
|
//Broadcaster,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
// 2. Add the BotAction to ModulesManager
|
||||||
|
botc1.add_to_modmgr(Arc::clone(&mgr)).await;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
async fn good_girl(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
|
@ -179,3 +198,29 @@ async fn babygirl(bot: BotAR, msg: PrivmsgMessage) {
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async fn routinelike(_bot: BotAR, msg: PrivmsgMessage) {
|
||||||
|
println!("routinelike triggered!"); // NOTE : This test function intends to print (e.g., to stdout) at fn call
|
||||||
|
botlog::debug(
|
||||||
|
"routinelike triggered!",
|
||||||
|
Some("experiments > routinelike()".to_string()),
|
||||||
|
Some(&msg),
|
||||||
|
);
|
||||||
|
|
||||||
|
// spawn an async block that runs independently from others
|
||||||
|
|
||||||
|
tokio::spawn( async {
|
||||||
|
for _ in 0..5 {
|
||||||
|
println!(">> Innterroutine triggered!");
|
||||||
|
sleep(Duration::from_secs_f64(5.0)).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
// lines are executed after in conjunction to the spawn
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue