Experiment with single threaded executor

This commit is contained in:
Maximilian Ammann 2022-09-08 11:16:55 +02:00
parent 7783493f09
commit 2c9f1d9be6
4 changed files with 22 additions and 9 deletions

View File

@ -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()

View File

@ -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"

View File

@ -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();

View File

@ -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(())