Skip to content

Commit

Permalink
replace lazy-static
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Nov 24, 2023
1 parent b3fb2f9 commit a0ca035
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion rgis-network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }

Expand Down
20 changes: 10 additions & 10 deletions rgis-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<tokio::runtime::Runtime> = sync::OnceLock::new();

pub struct FetchedFile {
pub name: String,
Expand Down Expand Up @@ -98,7 +91,14 @@ async fn await_future<Output>(
) -> 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")]
{
Expand Down

0 comments on commit a0ca035

Please sign in to comment.