worked

Crates.ioworked
lib.rsworked
version0.0.2
sourcesrc
created_at2024-05-03 01:29:56.209451
updated_at2024-05-06 04:07:39.818988
descriptionRun functions in Web Workers with ease
homepagehttps://github.com/tascord/worked
repositoryhttps://github.com/tascord/worked
max_upload_size
id1228286
size45,288
flora ~ 🏳️‍⚧️ ❤ 🦀 (tascord)

documentation

README

🤖 worked 🦀

Crates.io Version docs.rs

Run wasm code in workers, without blocking

use worked::*;

#[wasm_bindgen(start)]
pub async fn start() {
    for i in 0..20 {
        factorial(
            i.clone(), // <-- Function input
            move |o| gloo::console::log!(&format!("{i}! = {o}")) // <-- Callback
        ).await; // <-- Await the spawning of the worker
    }
}

#[worked("/pkg/wasm_workers.js")] // <-- Absolute path to your main wasm_bindgen export
pub fn factorial(n: i64) -> i64 { // <-- Functions can only take one input
    f(n)
}

#[wasm_bindgen]
pub fn f(n: i64) -> i64 {
    match n {
        0 => 1,
        _ => n * f(n - 1),
    }
}
Commit count: 10

cargo fmt