mirror of
https://gitlab.com/veilid/veilid.git
synced 2025-02-25 18:55:38 -06:00
refactor wasm tests
This commit is contained in:
@@ -87,15 +87,7 @@ pub fn system_boxed<'a, Out>(
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
cfg_if! {
|
||||
if #[cfg(target_arch = "wasm32")] {
|
||||
|
||||
// xxx: for now until wasm threads are more stable, and/or we bother with web workers
|
||||
pub fn get_concurrency() -> u32 {
|
||||
1
|
||||
}
|
||||
|
||||
} else {
|
||||
|
||||
if #[cfg(not(target_arch = "wasm32"))] {
|
||||
pub fn get_concurrency() -> u32 {
|
||||
std::thread::available_parallelism()
|
||||
.map(|x| x.get())
|
||||
@@ -104,7 +96,6 @@ cfg_if! {
|
||||
1
|
||||
}) as u32
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#![cfg(target_arch = "wasm32")]
|
||||
|
||||
use super::*;
|
||||
use core::sync::atomic::{AtomicI8, Ordering};
|
||||
use core::sync::atomic::{AtomicI8, AtomicU32, Ordering};
|
||||
use js_sys::{global, Reflect};
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
@@ -82,3 +82,19 @@ pub fn is_ipv6_supported() -> bool {
|
||||
*opt_supp = Some(supp);
|
||||
supp
|
||||
}
|
||||
|
||||
pub fn get_concurrency() -> u32 {
|
||||
static CACHE: AtomicU32 = AtomicU32::new(0);
|
||||
let cache = CACHE.load(Ordering::Acquire);
|
||||
if cache != 0 {
|
||||
return cache;
|
||||
}
|
||||
|
||||
let res = js_sys::eval("navigator.hardwareConcurrency")
|
||||
.map(|res| res.as_f64().unwrap_or(1.0f64) as u32)
|
||||
.unwrap_or(1);
|
||||
|
||||
CACHE.store(res, Ordering::Release);
|
||||
|
||||
res
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ pub fn setup() -> () {
|
||||
let mut builder = tracing_wasm::WASMLayerConfigBuilder::new();
|
||||
builder.set_report_logs_in_timings(false);
|
||||
builder.set_max_level(Level::TRACE);
|
||||
builder.set_console_config(tracing_wasm::ConsoleConfig::ReportWithConsoleColor);
|
||||
builder.set_console_config(tracing_wasm::ConsoleConfig::ReportWithoutConsoleColor);
|
||||
tracing_wasm::set_as_global_default_with_config(builder.build());
|
||||
} else {
|
||||
wasm_logger::init(wasm_logger::Config::default());
|
||||
|
||||
Reference in New Issue
Block a user