1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
use std::{
future::Future,
sync::atomic::{AtomicUsize, Ordering},
};
use crate::{
environment::OffscreenKernelEnvironment,
io::source_client::{HttpSourceClient, SourceClient},
platform::http_client::ReqwestHttpClient,
};
pub mod http_client;
pub mod scheduler;
pub mod trace;
pub fn run_multithreaded<F: Future>(future: F) -> F::Output {
tokio::runtime::Builder::new_multi_thread()
.enable_io()
.enable_time()
.thread_name_fn(|| {
static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
format!("maplibre-rs-pool-{id}")
})
.on_thread_start(|| {
#[cfg(feature = "trace")]
tracing_tracy::client::set_thread_name!("tokio-runtime-worker");
log::info!("Worker thread started")
})
.build()
.unwrap()
.block_on(future)
}
pub struct ReqwestOffscreenKernelEnvironment;
impl OffscreenKernelEnvironment for ReqwestOffscreenKernelEnvironment {
type HttpClient = ReqwestHttpClient;
fn create() -> Self {
ReqwestOffscreenKernelEnvironment
}
fn source_client(&self) -> SourceClient<Self::HttpClient> {
SourceClient::new(HttpSourceClient::new(ReqwestHttpClient::new(None)))
}
}