Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- name: Run doctest
run: cargo test --doc
run: cargo test --doc --all-features

test:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ readme = "README.md"
keywords = ["webworker", "parallelism", "wasm"]

[workspace.dependencies]
wasmworker = { version = "0.2", path = ".", features = ["serde"] }
wasmworker = { version = "0.2", path = ".", features = ["serde", "macros"] }
wasmworker-proc-macro = { version = "0.2", path = "proc-macro" }

[package]
Expand Down Expand Up @@ -65,3 +65,8 @@ wasmworker-proc-macro = { workspace = true }
[features]
default = ["serde"]
serde = []
macros = ["wasmworker-proc-macro"]

[dependencies.wasmworker-proc-macro]
workspace = true
optional = true
19 changes: 8 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,14 @@ In contrast to many other libraries like [wasm-bindgen-rayon](https://github.com
- [FAQ](#faq)

## Usage
The library consists of two crates:
- `wasmworker`: The main crate that also offers access to the webworker, as well as the worker pool and iterator extensions.
- `wasmworker-proc-macro`: This crate is needed to expose functions towards the web workers via the `#[webworker_fn]` macro.

### Setting up
To use this library, include both dependencies to your `Cargo.toml`.
To use this library, add the following dependency to your `Cargo.toml`.
Enable the `macros` feature to get access to the `#[webworker_fn]` and `#[webworker_channel_fn]` attribute macros.

```toml
[dependencies]
wasmworker = "0.2"
wasmworker-proc-macro = "0.2"
wasmworker = { version = "0.2", features = ["macros"] }
```

The `wasmworker` crate comes with a default feature called `serde`, which allows running any function on a web worker under the following two conditions:
Expand Down Expand Up @@ -59,7 +56,7 @@ This macro ensures that the functions are available to the web worker instances:

```rust,no_run
use serde::{Deserialize, Serialize};
use wasmworker_proc_macro::webworker_fn;
use wasmworker::webworker_fn;

/// An arbitrary type that is (de)serializable.
#[derive(Serialize, Deserialize)]
Expand All @@ -79,7 +76,7 @@ This object describes the function to the worker and can be safely obtained via

```rust,no_run
# use serde::{Deserialize, Serialize};
# use wasmworker_proc_macro::webworker_fn;
# use wasmworker::webworker_fn;
# #[derive(Serialize, Deserialize)]
# pub struct VecType(Vec<u8>);
# #[webworker_fn]
Expand All @@ -95,7 +92,7 @@ let ww_sort = webworker!(sort_vec);
We can instantiate our own workers and run functions on them:
```rust,no_run
# use serde::{Deserialize, Serialize};
# use wasmworker_proc_macro::webworker_fn;
# use wasmworker::webworker_fn;
# #[derive(Serialize, Deserialize, PartialEq, Debug)]
# pub struct VecType(Vec<u8>);
# #[webworker_fn]
Expand All @@ -117,7 +114,7 @@ It uses a round-robin scheduler (with the second option being a load based sched

```rust,no_run
# use serde::{Deserialize, Serialize};
# use wasmworker_proc_macro::webworker_fn;
# use wasmworker::webworker_fn;
# #[derive(Serialize, Deserialize, PartialEq, Debug)]
# pub struct VecType(Vec<u8>);
# #[webworker_fn]
Expand Down Expand Up @@ -153,7 +150,7 @@ First, define an async function with the `#[webworker_channel_fn]` macro:

```rust,ignore
use wasmworker::Channel;
use wasmworker_proc_macro::webworker_channel_fn;
use wasmworker::webworker_channel_fn;

#[derive(Serialize, Deserialize)]
pub struct Progress { pub percent: u8 }
Expand Down
1 change: 0 additions & 1 deletion demo/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ tokio = { version = "1.43", features = ["sync"] }
wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
wasmworker = { workspace = true }
wasmworker-proc-macro = { workspace = true }

[dependencies.web-sys]
features = [
Expand Down
2 changes: 1 addition & 1 deletion demo/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use send_wrapper::SendWrapper;
use serde::{Deserialize, Serialize};
use tokio::sync::OnceCell;
use wasm_bindgen::{prelude::wasm_bindgen, JsCast, UnwrapThrowExt};
use wasmworker::webworker_fn;
use wasmworker::{iter_ext::IteratorExt, webworker, worker_pool, WebWorker};
use wasmworker_proc_macro::webworker_fn;
use web_sys::{HtmlElement, HtmlInputElement};

/// A wrapper type to demonstrate serde functionality.
Expand Down
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub use web_sys::MessagePort;
// Re-export WebWorkerPool from pool module
pub use pool::WebWorkerPool;

#[cfg(feature = "macros")]
pub use wasmworker_proc_macro::*;

mod channel;
mod channel_task;
pub mod convert;
Expand Down
1 change: 0 additions & 1 deletion test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,3 @@ wasm-bindgen = "0.2"
wasm-bindgen-futures = "0.4"
web-sys = { version = "0.3", features = ["MessagePort"] }
wasmworker = { workspace = true }
wasmworker-proc-macro = { workspace = true }
2 changes: 1 addition & 1 deletion test/src/channel.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use wasmworker::webworker_channel_fn;
use wasmworker::{webworker_channel, worker_pool, Channel, WebWorker};
use wasmworker_proc_macro::webworker_channel_fn;

use crate::js_assert_eq;

Expand Down
2 changes: 1 addition & 1 deletion test/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use serde::{Deserialize, Serialize};
use wasmworker::webworker_fn;
use wasmworker::{has_worker_pool, iter_ext::IteratorExt, webworker, worker_pool, WebWorker};
use wasmworker_proc_macro::webworker_fn;

use crate::js_assert_eq;

Expand Down
2 changes: 1 addition & 1 deletion test/src/raw.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use wasm_bindgen::throw_str;
use wasmworker::webworker_fn;
use wasmworker::{
error::InitError, webworker, worker_pool, WebWorker, WebWorkerPool, WorkerPoolOptions,
};
use wasmworker_proc_macro::webworker_fn;

use crate::js_assert_eq;

Expand Down
Loading