File tree 2 files changed +9
-15
lines changed
2 files changed +9
-15
lines changed Original file line number Diff line number Diff line change 36
36
* when possible. The worker communicates with its parent using postMessage.
37
37
*/
38
38
39
- use js_sys:: { encode_uri_component , Array , Promise } ;
39
+ use js_sys:: { Array , Promise } ;
40
40
use std:: cell:: RefCell ;
41
41
use std:: sync:: atomic:: AtomicI32 ;
42
42
use wasm_bindgen:: prelude:: * ;
43
43
use wasm_bindgen:: JsCast ;
44
44
use web_sys:: { MessageEvent , Worker } ;
45
45
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
-
55
46
thread_local ! {
56
47
static HELPERS : RefCell <Vec <Worker >> = RefCell :: new( vec![ ] ) ;
57
48
}
@@ -62,11 +53,8 @@ fn alloc_helper() -> Worker {
62
53
return helper;
63
54
}
64
55
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) )
70
58
} )
71
59
}
72
60
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