Use async in threads with tokio

This commit is contained in:
Mylloon 2023-09-03 13:16:12 +02:00
parent 57d1956c67
commit 53e7a80561
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -3,21 +3,29 @@ use std::{
time::{Duration, Instant}, time::{Duration, Instant},
}; };
pub mod revanced; mod revanced;
fn main() { #[actix_web::main]
async fn main() {
let scheduler = thread::spawn(|| { let scheduler = thread::spawn(|| {
let wait_time = Duration::from_secs(60 * 60 * 12); let wait_time = Duration::from_secs(60 * 60 * 12);
// Tokio runtime
let rt = tokio::runtime::Builder::new_current_thread()
.enable_io()
.enable_time()
.build()
.unwrap();
loop { loop {
let start = Instant::now(); let start = Instant::now();
eprintln!("Scheduler starting"); eprintln!("Scheduler starting");
// Prepare threads // Prepare threads
let thread_a = thread::spawn(revanced::debug); let thread_a = thread::spawn(revanced::search);
// Run threads // Run threads
thread_a.join().expect("Thread A panicked"); rt.block_on(async { thread_a.join().expect("Thread A panicked").await });
let runtime = start.elapsed(); let runtime = start.elapsed();