#async-executor #async-task #async

wasm-rs-async-executor

Async executor for WebAssembly

14 releases (8 breaking)

0.9.0 Feb 21, 2021
0.7.0 Feb 18, 2021

#386 in WebAssembly

Download history 529/week @ 2023-11-29 549/week @ 2023-12-06 442/week @ 2023-12-13 349/week @ 2023-12-20 313/week @ 2023-12-27 334/week @ 2024-01-03 378/week @ 2024-01-10 498/week @ 2024-01-17 577/week @ 2024-01-24 416/week @ 2024-01-31 242/week @ 2024-02-07 377/week @ 2024-02-14 490/week @ 2024-02-21 427/week @ 2024-02-28 472/week @ 2024-03-06 270/week @ 2024-03-13

1,769 downloads per month
Used in 2 crates

MIT/Apache

35KB
687 lines

Async Executor for WebAssembly

Crate API Chat

There are a number of async task executors available in Rust's ecosystem. However, most (if not all?) of them rely on primitives that might not be available or optimal for WebAssembly deployment at the time.

Usage

Include this dependency in your Cargo.toml:

[dependencies]
wasm-rs-async-executor = "0.9.0"

wasm-rs-async-executor is expected to work on stable Rust, 1.49.0 and higher up. It may also work on earlier versions. This hasn't been tested yet.

Supported targets

Currently, it's been only tested on wasm32-unknown-unknown and, excluding cooperative functionality, it passes tests under wasmtime and wasmer with wasm32-wasi target. Further testing is to be completed.

Notes

Please note that this library hasn't received much analysis in terms of safety and soundness. Some of the caveats related to that might never be resolved completely. This is an ongoing development and the maintainer is aware of potential pitfalls. Any productive reports of unsafeties or unsoundness are welcomed (whether they can be resolved or simply walled with unsafe for end-user to note).

FAQ

Q: Why not just use wasm-bindgen-futures?

A: (short) In many cases, wasm-bindgen-futures is just fine

A: (longer) There are some subtle differences in the way wasm-rs-async-executor exposes its functionality. The core idea behind it is to expose a reasonable amount of explicit controls over the its operations. You need to run the executor explicitly, you can block on futures (again, explicitly -- which gives you a limited ability to do scoped futures). It does come with minor trade-offs. For example, if you want to use async APIs from your host environment, you can't simply await on then, as the executor won't yield to the browser until told to do so. However, this is typically solved by simply running a permanent task that loops yielding to the browser.

Ultimately, if this amount of control is beneficial for your case, then perhaps this executor is waranted. It is also important to note that currently wasm-rs-async-executor does not support WebAssembly multi-threading in any way. wasm-bindgen-futures does, if the standard library is built with support for it. It is planned to support this, but hasn't been high priority so far due to current state of things in Rust.

License

Licensed under either of

Dependencies

~0.6–3MB
~56K SLoC