diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-06 09:13:54 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-06 09:13:54 +0200 |
| commit | ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0 (patch) | |
| tree | 76be6a8b1596ea1e74dbf7085b85214c2c83e69a /06_storage/script.mjs | |
| parent | 961c3470d7e9bdf5efbe0509f586be75d7052d8b (diff) | |
| download | emscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.tar.gz emscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.zip | |
Added example 6
Diffstat (limited to '06_storage/script.mjs')
| -rw-r--r-- | 06_storage/script.mjs | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/06_storage/script.mjs b/06_storage/script.mjs new file mode 100644 index 0000000..1238371 --- /dev/null +++ b/06_storage/script.mjs | |||
| @@ -0,0 +1,20 @@ | |||
| 1 | var aInput = document.getElementById("aInput"); | ||
| 2 | var bInput = document.getElementById("bInput"); | ||
| 3 | var button = document.getElementById("goButton"); | ||
| 4 | var resultText = document.getElementById("resultText"); | ||
| 5 | |||
| 6 | var worker = new Worker("./worker.mjs", { type: "module" }); | ||
| 7 | |||
| 8 | button.addEventListener("click", () => worker.postMessage({ | ||
| 9 | a: Number(aInput.value), | ||
| 10 | b: Number(bInput.value) | ||
| 11 | })); | ||
| 12 | |||
| 13 | worker.onmessage = (e) => { | ||
| 14 | if (e.data.type == "response") | ||
| 15 | resultText.innerText = e.data.message; | ||
| 16 | else if (e.data.type == "readySignal") { | ||
| 17 | button.disabled = false; | ||
| 18 | button.innerText = "Compute" | ||
| 19 | } | ||
| 20 | }; | ||
