Skip to content

An error occurred: Failed to execute 'postMessage' on 'Worker': #<Memory> could not be cloned. #24

@foreinbug

Description

@foreinbug

environment:

  • rustc 1.80.0-nightly (72fdf913c 2024-06-05)
  • cargo 1.80.0-nightly (34a6a87d8 2024-06-04)
  • wasm-pack 0.12.1
  • nightly-x86_64-pc-windows-msvc

No cross domain, use self-signed HTTPS;

cargo.toml

[package]
name = "simple"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
wasm_thread = { version = "0.3.0", default-features = false }
log = "0.4"
wasm-bindgen = "0.2"
console_log = { version = "1.0", features = ["color"] }
console_error_panic_hook = "0.1"

src/lib.rs

use std::time::Duration;

use wasm_bindgen::prelude::*;
use wasm_thread as thread;

#[wasm_bindgen(start)]
fn main() {
    console_log::init().unwrap();
    console_error_panic_hook::set_once();

    for _ in 0..2 {
        thread::spawn(|| {
            for i in 1..3 {
                log::info!(
                    "hi number {} from the spawned thread {:?}!",
                    i,
                    thread::current().id()
                );
                thread::sleep(Duration::from_millis(1));
            }
        });
    }

    for i in 1..3 {
        log::info!(
            "hi number {} from the main thread {:?}!",
            i,
            thread::current().id()
        );
    }
}

build.ps1

wasm-pack build --dev --out-dir ./module/target --target web --features wasm_thread/es_modules
simple.js:338 
 panicked at C:\Users\ASUS\.cargo\registry\src\index.crates.io-6f17d22bba15001f\wasm_thread-0.3.0\src\wasm32\mod.rs:349:10:
called `Result::unwrap()` on an `Err` value: JsValue(DataCloneError: Failed to execute 'postMessage' on 'Worker': #<Memory> could not be cloned.
Error: Failed to execute 'postMessage' on 'Worker': #<Memory> could not be cloned.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions