added lazy thread handling to tokio runtime

This commit is contained in:
Valmo Trindade
2024-09-21 23:38:51 -03:00
parent e9ac9978aa
commit 3c40fa7166
3 changed files with 12 additions and 3 deletions

View File

@@ -1,8 +1,15 @@
use once_cell::sync::Lazy;
use tokio::runtime::Runtime;
use crate::{
structs::LoginPayload,
util::{blocking_fetch_auth_token, parse_login_to_payload},
};
pub static RUNTIME: Lazy<Runtime> = Lazy::new(|| {
Runtime::new().expect("Failed to build the Tokio Runtime")
});
pub fn get_auth_token(login_payload: LoginPayload) -> String {
let api_address = login_payload.address.clone();
let login_info = parse_login_to_payload(login_payload);
@@ -14,7 +21,8 @@ pub(crate) mod markers {
use crate::{structs::Marker, util::{async_post_markers, parse_marker_to_payload}};
use log::{error, info};
use std::thread;
use tokio::runtime::Runtime;
use super::RUNTIME;
pub fn get(placeholder: String) -> &'static str {
info!("{}", placeholder);
@@ -24,8 +32,7 @@ pub(crate) mod markers {
pub fn post(data: Vec<Marker>) -> &'static str {
thread::spawn(move || {
let rt = Runtime::new().unwrap();
rt.block_on(async_post_markers(data));
RUNTIME.block_on(async_post_markers(data));
});
"loading"