Skip to content

Commit

Permalink
Use generics instead of dynamic dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
c-git committed Jan 31, 2024
1 parent 10b5e31 commit cab8f10
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,21 @@ impl eframe::App for BrowseApp {
}

#[cfg(target_arch = "wasm32")]
fn execute(
f: impl std::future::Future<Output = Option<String>> + 'static,
) -> Option<poll_promise::Promise<Option<String>>> {
fn execute<F>(f: F) -> Option<poll_promise::Promise<Option<String>>>
where
F: std::future::Future<Output = Option<String>> + 'static,
{
Some(poll_promise::Promise::spawn_local(f))
}

#[cfg(not(target_arch = "wasm32"))]
fn execute(
f: impl std::future::Future<Output = Option<String>> + std::marker::Send + 'static,
) -> SaveLoadPromise {
fn execute<F>(f: F) -> SaveLoadPromise
where
F: std::future::Future<Output = Option<String>> + std::marker::Send + 'static,
{
Some(poll_promise::Promise::spawn_async(f))
}

// fn execute<F: std::future::Future<Output = ()> + 'static>(f: F) {
// wasm_bindgen_futures::spawn_local(f);
// }

0 comments on commit cab8f10

Please sign in to comment.