From a0ca03552d14f4c3bc77cf96a8be50578d5aa471 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Fri, 24 Nov 2023 10:19:04 -0500 Subject: [PATCH] replace lazy-static --- Cargo.lock | 1 - rgis-network/Cargo.toml | 1 - rgis-network/src/lib.rs | 20 ++++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f4ad41a..a29ebd3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4035,7 +4035,6 @@ dependencies = [ "bevy_jobs", "bytes", "futures-util", - "lazy_static", "reqwest", "thiserror", "tokio", diff --git a/rgis-network/Cargo.toml b/rgis-network/Cargo.toml index 7b309a3..709148b 100644 --- a/rgis-network/Cargo.toml +++ b/rgis-network/Cargo.toml @@ -16,7 +16,6 @@ bevy = { version = "0.12", default-features = false, features = [ ] } bytes = "1" futures-util = "0.3" -lazy_static = "1" reqwest = { version = "0.11", features = ["stream"] } diff --git a/rgis-network/src/lib.rs b/rgis-network/src/lib.rs index 2370931..d835d71 100644 --- a/rgis-network/src/lib.rs +++ b/rgis-network/src/lib.rs @@ -7,17 +7,10 @@ )] use futures_util::StreamExt; -use std::io; +use std::{io, sync}; #[cfg(not(target_arch = "wasm32"))] -lazy_static::lazy_static! { - pub static ref TOKIO_RUNTIME: tokio::runtime::Runtime = { - tokio::runtime::Builder::new_multi_thread() - .enable_all() - .build() - .unwrap() - }; -} +const TOKIO_RUNTIME: sync::OnceLock = sync::OnceLock::new(); pub struct FetchedFile { pub name: String, @@ -98,7 +91,14 @@ async fn await_future( ) -> Output { #[cfg(not(target_arch = "wasm32"))] { - TOKIO_RUNTIME.block_on(future) + TOKIO_RUNTIME + .get_or_init(|| { + tokio::runtime::Builder::new_multi_thread() + .enable_all() + .build() + .unwrap() + }) + .block_on(future) } #[cfg(target_arch = "wasm32")] {