mirror of
https://github.com/valmojr/armatak.git
synced 2026-06-13 15:23:28 +00:00
added lazy thread handling to tokio runtime
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -88,6 +88,7 @@ dependencies = [
|
|||||||
"arma-rs",
|
"arma-rs",
|
||||||
"log",
|
"log",
|
||||||
"log4rs",
|
"log4rs",
|
||||||
|
"once_cell",
|
||||||
"regex",
|
"regex",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ edition = "2021"
|
|||||||
arma-rs = "1.10.4"
|
arma-rs = "1.10.4"
|
||||||
log = "0.4.22"
|
log = "0.4.22"
|
||||||
log4rs = "1.3.0"
|
log4rs = "1.3.0"
|
||||||
|
once_cell = "1.19.0"
|
||||||
regex = "1.10.6"
|
regex = "1.10.6"
|
||||||
reqwest = {version = "0.12.7", features = ["blocking"]}
|
reqwest = {version = "0.12.7", features = ["blocking"]}
|
||||||
serde = { version = "1.0.210", features = ["derive"] }
|
serde = { version = "1.0.210", features = ["derive"] }
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
|
use once_cell::sync::Lazy;
|
||||||
|
use tokio::runtime::Runtime;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
structs::LoginPayload,
|
structs::LoginPayload,
|
||||||
util::{blocking_fetch_auth_token, parse_login_to_payload},
|
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 {
|
pub fn get_auth_token(login_payload: LoginPayload) -> String {
|
||||||
let api_address = login_payload.address.clone();
|
let api_address = login_payload.address.clone();
|
||||||
let login_info = parse_login_to_payload(login_payload);
|
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 crate::{structs::Marker, util::{async_post_markers, parse_marker_to_payload}};
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use tokio::runtime::Runtime;
|
|
||||||
|
use super::RUNTIME;
|
||||||
|
|
||||||
pub fn get(placeholder: String) -> &'static str {
|
pub fn get(placeholder: String) -> &'static str {
|
||||||
info!("{}", placeholder);
|
info!("{}", placeholder);
|
||||||
@@ -24,8 +32,7 @@ pub(crate) mod markers {
|
|||||||
|
|
||||||
pub fn post(data: Vec<Marker>) -> &'static str {
|
pub fn post(data: Vec<Marker>) -> &'static str {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let rt = Runtime::new().unwrap();
|
RUNTIME.block_on(async_post_markers(data));
|
||||||
rt.block_on(async_post_markers(data));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
"loading"
|
"loading"
|
||||||
|
|||||||
Reference in New Issue
Block a user