fix: Don't spawn threads
This commit is contained in:
+29
-16
@@ -1,4 +1,4 @@
|
||||
use std::time::Duration;
|
||||
use std::{sync::Arc, time::Duration};
|
||||
|
||||
use atem_connection_rs::{
|
||||
atem_lib::atem_socket::AtemSocket,
|
||||
@@ -10,7 +10,7 @@ use atem_connection_rs::{
|
||||
|
||||
use clap::Parser;
|
||||
use color_eyre::Report;
|
||||
use tokio::time::sleep;
|
||||
use tokio::{task::yield_now, time::sleep};
|
||||
|
||||
/// ATEM Rust Library Test App
|
||||
#[derive(Parser, Debug)]
|
||||
@@ -30,27 +30,40 @@ async fn main() {
|
||||
let switch_to_source_1 = ProgramInput::new(0, 1);
|
||||
let switch_to_source_2 = ProgramInput::new(0, 2);
|
||||
|
||||
let mut atem = AtemSocket::new();
|
||||
atem.connect(args.ip, 9910).await.ok();
|
||||
let atem = tokio::sync::RwLock::new(AtemSocket::default());
|
||||
let atem = Arc::new(atem);
|
||||
let atem_thread = atem.clone();
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
atem_thread.write().await.tick().await;
|
||||
|
||||
yield_now().await;
|
||||
}
|
||||
});
|
||||
atem.write().await.connect(args.ip, 9910).await.ok();
|
||||
|
||||
let mut tracking_id = 0;
|
||||
loop {
|
||||
tracking_id += 1;
|
||||
sleep(Duration::from_millis(5000)).await;
|
||||
atem.send_command(
|
||||
&switch_to_source_1.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_1.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
.await;
|
||||
atem.write()
|
||||
.await
|
||||
.send_command(
|
||||
&switch_to_source_1.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_1.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
.await;
|
||||
tracking_id += 1;
|
||||
sleep(Duration::from_millis(5000)).await;
|
||||
atem.send_command(
|
||||
&switch_to_source_2.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_2.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
.await;
|
||||
atem.write()
|
||||
.await
|
||||
.send_command(
|
||||
&switch_to_source_2.payload(atem_connection_rs::enums::ProtocolVersion::Unknown),
|
||||
switch_to_source_2.get_raw_name(),
|
||||
tracking_id,
|
||||
)
|
||||
.await;
|
||||
tracking_id += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user