mirror of
https://github.com/maplibre/maplibre-rs.git
synced 2025-12-08 19:05:57 +00:00
Experiment with single threaded executor
This commit is contained in:
parent
7783493f09
commit
2c9f1d9be6
@ -142,9 +142,12 @@ where
|
||||
.schedule(Box::new(move || {
|
||||
Box::pin(async move {
|
||||
match client.fetch(&coords).await {
|
||||
Ok(data) => state
|
||||
.process_tile(request_id, data.into_boxed_slice())
|
||||
.unwrap(),
|
||||
Ok(data) => {
|
||||
log::warn!("fetching done");
|
||||
state
|
||||
.process_tile(request_id, data.into_boxed_slice())
|
||||
.unwrap()
|
||||
}
|
||||
Err(e) => {
|
||||
log::error!("{:?}", &e);
|
||||
state.tile_unavailable(&coords, request_id).unwrap()
|
||||
|
||||
@ -38,6 +38,7 @@ wasm-bindgen = "0.2.81"
|
||||
wasm-bindgen-futures = "0.4.31"
|
||||
console_log = { version = "0.2.0", features = ["color"] }
|
||||
tracing-wasm = { version = "0.2.1", optional = true } # FIXME: Low quality dependency
|
||||
futures = "0.3.24"
|
||||
|
||||
[dev-dependencies]
|
||||
wasm-bindgen-test = "0.3.31"
|
||||
|
||||
@ -26,7 +26,9 @@ impl WHATWGFetchHttpClient {
|
||||
let scope = global.dyn_into::<WorkerGlobalScope>().unwrap();
|
||||
|
||||
// Call fetch on global scope
|
||||
log::warn!("starting fetching");
|
||||
let maybe_response = JsFuture::from(scope.fetch_with_request(&request)).await?;
|
||||
log::warn!("fetching done 1");
|
||||
assert!(maybe_response.is_instance_of::<Response>());
|
||||
let response: Response = maybe_response.dyn_into().unwrap();
|
||||
|
||||
|
||||
@ -1,11 +1,13 @@
|
||||
use futures::executor::LocalPool;
|
||||
use futures::task::{LocalSpawnExt, SpawnExt};
|
||||
use log::warn;
|
||||
use std::future::Future;
|
||||
|
||||
use super::pool::WorkerPool;
|
||||
use maplibre::{error::Error, io::scheduler::ScheduleMethod};
|
||||
use wasm_bindgen::{prelude::*, JsCast};
|
||||
use web_sys::Worker;
|
||||
|
||||
use super::pool::WorkerPool;
|
||||
|
||||
pub struct WebWorkerPoolScheduleMethod {
|
||||
pool: WorkerPool,
|
||||
}
|
||||
@ -38,10 +40,15 @@ impl ScheduleMethod for WebWorkerPoolScheduleMethod {
|
||||
{
|
||||
self.pool
|
||||
.execute(move || {
|
||||
wasm_bindgen_futures::future_to_promise(async move {
|
||||
future_factory().await;
|
||||
Ok(JsValue::undefined())
|
||||
})
|
||||
pool.spawner()
|
||||
.spawn_local(async move {
|
||||
future_factory().await;
|
||||
})
|
||||
.unwrap();
|
||||
|
||||
warn!("Running tasks");
|
||||
pool.run_until_stalled();
|
||||
warn!("All tasks done");
|
||||
})
|
||||
.unwrap();
|
||||
Ok(())
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user