2020-09-06 17:10:15 +00:00
|
|
|
/* Worker code for test_worker.js */
|
|
|
|
import * as std from "std";
|
|
|
|
import * as os from "os";
|
|
|
|
|
|
|
|
var parent = os.Worker.parent;
|
|
|
|
|
|
|
|
function handle_msg(e) {
|
|
|
|
var ev = e.data;
|
|
|
|
// print("child_recv", JSON.stringify(ev));
|
|
|
|
switch(ev.type) {
|
|
|
|
case "abort":
|
|
|
|
parent.postMessage({ type: "done" });
|
|
|
|
break;
|
|
|
|
case "sab":
|
|
|
|
/* modify the SharedArrayBuffer */
|
|
|
|
ev.buf[2] = 10;
|
|
|
|
parent.postMessage({ type: "sab_done", buf: ev.buf });
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function worker_main() {
|
|
|
|
var i;
|
2023-11-12 09:01:40 +00:00
|
|
|
|
2020-09-06 17:10:15 +00:00
|
|
|
parent.onmessage = handle_msg;
|
|
|
|
for(i = 0; i < 10; i++) {
|
2023-11-12 09:01:40 +00:00
|
|
|
parent.postMessage({ type: "num", num: i });
|
2020-09-06 17:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
worker_main();
|