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/worker.mjs | |
| parent | 961c3470d7e9bdf5efbe0509f586be75d7052d8b (diff) | |
| download | emscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.tar.gz emscripten-tutorial-ab0db69a7b11ba1a9dc52d50c94e9e321b70ebf0.zip | |
Added example 6
Diffstat (limited to '')
| -rw-r--r-- | 06_storage/worker.mjs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/06_storage/worker.mjs b/06_storage/worker.mjs new file mode 100644 index 0000000..929fabc --- /dev/null +++ b/06_storage/worker.mjs | |||
| @@ -0,0 +1,22 @@ | |||
| 1 | import Primes from "./build/primes.mjs"; | ||
| 2 | |||
| 3 | var primes = await Primes(); | ||
| 4 | |||
| 5 | const logPtr = primes.addFunction((cstr) => { | ||
| 6 | const str = primes.UTF8ToString(cstr); | ||
| 7 | console.log(str); | ||
| 8 | postMessage({ message: str }); | ||
| 9 | }, "vp"); | ||
| 10 | |||
| 11 | onmessage = (e) => { | ||
| 12 | const count = primes._primes_in_range(e.data.a, e.data.b, logPtr); | ||
| 13 | postMessage({ | ||
| 14 | type: "response", | ||
| 15 | message: "There are " + count + " primes between " + | ||
| 16 | e.data.a + " and " + e.data.b | ||
| 17 | }); | ||
| 18 | }; | ||
| 19 | |||
| 20 | primes.fileSystemLoaded.then(() => { | ||
| 21 | postMessage({ type: "readySignal" }); | ||
| 22 | }); | ||
