1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//! # wasmworker
//!
//! Parallelize tasks on WebAssembly without `SharedArrayBuffer`.
//!
//! See the [README](https://github.com/paberr/wasmworker) for full documentation
//! including bundler setup and FAQ.
//!
//! ## Quick start
//!
//! Add to your `Cargo.toml`:
//!
//! ```toml
//! [dependencies]
//! wasmworker = { version = "0.2", features = ["macros"] }
//! ```
//!
//! ### Defining worker functions
//!
//! ```no_run
//! use serde::{Deserialize, Serialize};
//! use wasmworker::{webworker, webworker_fn};
//!
//! /// An arbitrary type that is (de)serializable.
//! #[derive(Serialize, Deserialize)]
//! pub struct VecType(Vec<u8>);
//!
//! /// A sort function on a custom type.
//! #[webworker_fn]
//! pub fn sort_vec(mut v: VecType) -> VecType {
//! v.0.sort();
//! v
//! }
//!
//! # fn main() {
//! // Obtain a type-safe handle to the function:
//! let ww_sort = webworker!(sort_vec);
//! # }
//! ```
//!
//! ### Running tasks
//!
//! ```no_run
//! # use serde::{Deserialize, Serialize};
//! # use wasmworker::{webworker, webworker_fn, WebWorker};
//! #
//! # #[derive(Serialize, Deserialize, PartialEq, Debug)]
//! # pub struct VecType(Vec<u8>);
//! #
//! # #[webworker_fn]
//! # pub fn sort_vec(mut v: VecType) -> VecType {
//! # v.0.sort();
//! # v
//! # }
//! #
//! # async fn example() {
//! let worker = WebWorker::new(None).await.expect("Couldn't create worker");
//! let sorted = worker.run(webworker!(sort_vec), &VecType(vec![3, 1, 2])).await;
//! assert_eq!(sorted.0, vec![1, 2, 3]);
//! # }
//! # fn main() {}
//! ```
//!
//! ```no_run
//! # use serde::{Deserialize, Serialize};
//! # use wasmworker::{webworker, webworker_fn, worker_pool};
//! #
//! # #[derive(Serialize, Deserialize, PartialEq, Debug)]
//! # pub struct VecType(Vec<u8>);
//! #
//! # #[webworker_fn]
//! # pub fn sort_vec(mut v: VecType) -> VecType {
//! # v.0.sort();
//! # v
//! # }
//! #
//! # async fn example() {
//! let worker_pool = worker_pool().await;
//! let sorted = worker_pool.run(webworker!(sort_vec), &VecType(vec![3, 1, 2])).await;
//! assert_eq!(sorted.0, vec![1, 2, 3]);
//! # }
//! # fn main() {}
//! ```
//!
//! ### Configuring the worker pool
//!
//! ```no_run
//! # use wasmworker::{init_worker_pool, WorkerPoolOptions};
//! #
//! # async fn startup() {
//! let mut options = WorkerPoolOptions::new();
//! options.num_workers = Some(2); // Default is navigator.hardwareConcurrency
//! init_worker_pool(options).await.expect("Worker pool already initialized");
//! # }
//! # fn main() {}
//! ```
pub use Channel;
pub use ChannelTask;
pub use ;
pub use WorkerPoolOptions;
pub use WebWorker;
pub use MessagePort;
// Re-export WebWorkerPool from pool module
pub use WebWorkerPool;
pub use *;