Skip to content

Commit

Permalink
Merge pull request #1 from thedodd/worker-fixes
Browse files Browse the repository at this point in the history
Update worker PR
  • Loading branch information
kristoff3r authored Feb 24, 2022
2 parents f911eda + e25b0ee commit a68f045
Show file tree
Hide file tree
Showing 12 changed files with 526 additions and 46 deletions.
317 changes: 317 additions & 0 deletions examples/webworker-gloo/Cargo.lock

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

11 changes: 11 additions & 0 deletions examples/webworker-gloo/Cargo.toml
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"
14 changes: 14 additions & 0 deletions examples/webworker-gloo/index.html
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>
20 changes: 20 additions & 0 deletions examples/webworker-gloo/src/bin/app.rs
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));
}
11 changes: 11 additions & 0 deletions examples/webworker-gloo/src/bin/worker.rs
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();
}
Loading

0 comments on commit a68f045

Please sign in to comment.