forked from cory/tildefriends
Cory McWilliams
2b7077ca70
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4765 ed5197a5-7fde-0310-b194-c3ffbd925b24
33 lines
742 B
JavaScript
33 lines
742 B
JavaScript
/* 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" });
|
|
parent.onMessage = null; /* terminate the worker */
|
|
break;
|
|
case "sab":
|
|
/* modify the SharedArrayBuffer */
|
|
ev.buf[2] = 10;
|
|
parent.postMessage({ type: "sab_done", buf: ev.buf });
|
|
break;
|
|
}
|
|
}
|
|
|
|
function worker_main() {
|
|
var i;
|
|
|
|
parent.onmessage = handle_msg;
|
|
for(i = 0; i < 10; i++) {
|
|
parent.postMessage({ type: "num", num: i });
|
|
}
|
|
}
|
|
|
|
worker_main();
|