File tree Expand file tree Collapse file tree 2 files changed +9
-15
lines changed
Expand file tree Collapse file tree 2 files changed +9
-15
lines changed Original file line number Diff line number Diff line change 3636 * when possible. The worker communicates with its parent using postMessage.
3737 */
3838
39- use js_sys:: { encode_uri_component , Array , Promise } ;
39+ use js_sys:: { Array , Promise } ;
4040use std:: cell:: RefCell ;
4141use std:: sync:: atomic:: AtomicI32 ;
4242use wasm_bindgen:: prelude:: * ;
4343use wasm_bindgen:: JsCast ;
4444use web_sys:: { MessageEvent , Worker } ;
4545
46- const HELPER_CODE : & ' static str = "
47- onmessage = function (ev) {
48- let [ia, index, value] = ev.data;
49- ia = new Int32Array(ia.buffer);
50- let result = Atomics.wait(ia, index, value);
51- postMessage(result);
52- };
53- " ;
54-
5546thread_local ! {
5647 static HELPERS : RefCell <Vec <Worker >> = RefCell :: new( vec![ ] ) ;
5748}
@@ -62,11 +53,8 @@ fn alloc_helper() -> Worker {
6253 return helper;
6354 }
6455
65- let mut initialization_string = "data:application/javascript," . to_owned ( ) ;
66- let encoded: String = encode_uri_component ( HELPER_CODE ) . into ( ) ;
67- initialization_string. push_str ( & encoded) ;
68-
69- Worker :: new ( & initialization_string) . unwrap_or_else ( |js| wasm_bindgen:: throw_val ( js) )
56+ let worker_url = wasm_bindgen:: link_to!( module = "/src/task/worker.js" ) . unwrap ( ) ;
57+ Worker :: new ( & worker_url) . unwrap_or_else ( |js| wasm_bindgen:: throw_val ( js) )
7058 } )
7159}
7260
Original file line number Diff line number Diff line change 1+ onmessage = function ( ev ) {
2+ let [ ia , index , value ] = ev . data ;
3+ ia = new Int32Array ( ia . buffer ) ;
4+ let result = Atomics . wait ( ia , index , value ) ;
5+ postMessage ( result ) ;
6+ } ;
You can’t perform that action at this time.
0 commit comments