···11+class Channel{pending;waiting;constructor(){this.pending=[],this.waiting=[]}send(data){if(this.waiting.length>0){this.waiting.shift()(data);return}this.pending.push(data)}async recv(){return new Promise((resolve,_reject)=>{if(this.pending.length>0){resolve(this.pending.shift());return}this.waiting.push(resolve)})}}class WeakDioxusChannel{inner;constructor(channel){this.inner=new WeakRef(channel)}rustSend(data){let channel=this.inner.deref();if(channel)channel.rustSend(data)}async rustRecv(){let channel=this.inner.deref();if(channel)return await channel.rustRecv()}}class DioxusChannel{weak(){return new WeakDioxusChannel(this)}}globalThis.__nextChannelId=0;globalThis.__channels=[];class WebDioxusChannel extends DioxusChannel{js_to_rust;rust_to_js;owner;id;constructor(owner){super();this.owner=owner,this.js_to_rust=new Channel,this.rust_to_js=new Channel,this.id=globalThis.__nextChannelId,globalThis.__channels[this.id]=this,globalThis.__nextChannelId+=1}weak(){return new WeakDioxusChannel(this)}async recv(){return await this.rust_to_js.recv()}send(data){this.js_to_rust.send(data)}rustSend(data){this.rust_to_js.send(data)}async rustRecv(){return await this.js_to_rust.recv()}close(){globalThis.__channels[this.id]=null}}export{WebDioxusChannel,WeakDioxusChannel};
+19
crates/weaver-app/src/bin/editor_worker.rs
···11+//! Entry point for the editor web worker.
22+//!
33+//! This binary is compiled separately and loaded by the main app
44+//! to handle CPU-intensive editor operations off the main thread.
55+66+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
77+fn main() {
88+ console_error_panic_hook::set_once();
99+1010+ use gloo_worker::Registrable;
1111+ use weaver_app::components::editor::EditorWorker;
1212+1313+ EditorWorker::registrar().register();
1414+}
1515+1616+#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1717+fn main() {
1818+ eprintln!("This binary is only meant to run as a WASM web worker");
1919+}
+19
crates/weaver-app/src/bin/embed_worker.rs
···11+//! Entry point for the embed web worker.
22+//!
33+//! This binary is compiled separately and loaded by the main app
44+//! to fetch and cache AT Protocol embeds off the main thread.
55+66+#[cfg(all(target_family = "wasm", target_os = "unknown"))]
77+fn main() {
88+ console_error_panic_hook::set_once();
99+1010+ use gloo_worker::Registrable;
1111+ use weaver_app::components::editor::EmbedWorker;
1212+1313+ EmbedWorker::registrar().register();
1414+}
1515+1616+#[cfg(not(all(target_family = "wasm", target_os = "unknown")))]
1717+fn main() {
1818+ eprintln!("This binary is only meant to run as a WASM web worker");
1919+}