Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASM: add abstraction for tokio::spawn #2442

Merged
merged 2 commits into from
Jun 3, 2024
Merged

WASM: add abstraction for tokio::spawn #2442

merged 2 commits into from
Jun 3, 2024

Conversation

styppo
Copy link
Member

@styppo styppo commented May 8, 2024

  • Add a utility function spawn which calls wasm_bindgen_futures::spawn_local for WASM targets and tokio::spawn otherwise.
  • Remove TaskExecutor.

Closes #2434.

Copy link
Member

@sisou sisou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved from a functional standpoint: web-client works

Copy link
Contributor

@hrxi hrxi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. And it even has a negative diff!

utils/Cargo.toml Outdated Show resolved Hide resolved
@@ -23,7 +23,7 @@ workspace = true
async-trait = "0.1"
futures = { package = "futures-util", version = "0.3" }
futures-executor = { version = "0.3" }
instant = { version = "0.1", features = [ "wasm-bindgen" ] }
instant = { version = "0.1", features = ["wasm-bindgen"] }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we would want to introduce a feature called wasm_bindgen that enables this other feature such that it doesn't always get pulled. Something like:

[features]
wasm-bindgen = ["instant/wasm-bindgen"]

utils/src/spawn/mod.rs Show resolved Hide resolved
utils/src/spawn/mod.rs Show resolved Hide resolved
utils/src/spawn/mod.rs Show resolved Hide resolved
utils/src/spawn/mod.rs Show resolved Hide resolved
utils/Cargo.toml Outdated Show resolved Hide resolved
.expect("Client initialization failed");
let mut client = nimiq::client::Client::from_config(config)
.await
.expect("Client initialization failed");
log::info!("Web client initialized");

// Start consensus.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@styppo the web-client crate has a bunch of wasm_bindgen::spawn_locals. Those can get replaced with the new spawn abstraction too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In that case it is guaranteed for it to not be a tokio::spawn though as the web client will be compiled for the wasm target always. It could be done, but it would not add much I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's true but for consistency across the codebase using the abstraction as much makes sense. For example if you want to alter the impl behind the abstraction maybe later in the far future.

@styppo styppo added this to the Nimiq PoS Mainnet milestone May 20, 2024
@sisou sisou added the WASM label May 22, 2024
@styppo styppo force-pushed the styppo/spawn branch 2 times, most recently from 36e81ce to c1d996a Compare May 31, 2024 16:09
- Add a utility function `spawn` which calls `wasm_bindgen_futures::spawn_local`
  for WASM targets and `tokio::spawn` otherwise.
- Remove `TaskExecutor`.
@styppo styppo merged commit c6f802f into albatross Jun 3, 2024
5 checks passed
@styppo styppo deleted the styppo/spawn branch June 3, 2024 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify task executors for web based and not web clients
6 participants