This library allows to compile and deploy yew worker with wasm32-wasi target. It allows to compile and run POSIX-like applications, having access to timer, random numbers and to emulated file system (memfs).
On some operations wasi workers run faster than wasm-bindgen or stdweb.
Cargo.toml
wasi-worker-yew = "0.4"
src/bin/worker.rs
``` use wasiworkeryew::{ThreadedWASI, WASIAgent}; use yew::agent::*; use wasi_worker::{FileOptions, ServiceOptions, ServiceWorker};
pub struct MyAgent;
impl Agent for MyAgent {
type Reach = Public;
type Message = String;
type Input = String;
type Output = String;
fn create(link: AgentLink
fn main() {
let opt = ServiceOptions::default().withcleanup();
ServiceWorker::initialize(opt)
.expect("ServiceWorker::initialize");
ServiceWorker::setmessage_handler(Box::new(WASIAgent::
To simplify build and deploy you may use wasi-worker-cli:
cargo install wasi-worker-cli --force
Deployment script will place compiled and optimized worker target and JS glue code under ./dist
:
wasiworker deploy