-
Notifications
You must be signed in to change notification settings - Fork 258
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add data-type attribute to rust links This allows web workers to be included in `index.html`. Since this makes the rust-worker attribute unnecessary it has been removed. Also adds an example showing basic usage and updates the documentation. * Adjust worker file naming and update samples Co-authored-by: Dominik Nakamura <[email protected]>
- Loading branch information
1 parent
d46ba85
commit b989bc9
Showing
17 changed files
with
825 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "webworker-gloo" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
console_error_panic_hook = "0.1.7" | ||
gloo-worker = "0.1.0" | ||
wasm-bindgen = "0.2.79" | ||
web-sys = { version = "0.3.56", features = ["console"] } | ||
wee_alloc = "0.4.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<title>Trunk | Web worker | Gloo</title> | ||
|
||
<base data-trunk-public-url /> | ||
</head> | ||
<body> | ||
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="app" data-type="main" /> | ||
<link data-trunk rel="rust" href="Cargo.toml" data-wasm-opt="z" data-bin="worker" data-type="worker" /> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use std::rc::Rc; | ||
|
||
use gloo_worker::Bridged; | ||
use webworker_gloo::Multiplier; | ||
|
||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
fn main() { | ||
console_error_panic_hook::set_once(); | ||
|
||
let bridge = Multiplier::bridge(Rc::new(Box::new(|((a, b), result)| { | ||
web_sys::console::log_1(&format!("{a} x {b} = {result}").into()); | ||
}))); | ||
let bridge = Box::leak(bridge); | ||
|
||
bridge.send((2, 5)); | ||
bridge.send((3, 3)); | ||
bridge.send((50, 5)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
use gloo_worker::PublicWorker; | ||
use webworker_gloo::Multiplier; | ||
|
||
#[global_allocator] | ||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; | ||
|
||
fn main() { | ||
console_error_panic_hook::set_once(); | ||
|
||
Multiplier::register(); | ||
} |
Oops, something went wrong.