diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 10:13:28 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-06-05 10:13:28 +0200 |
| commit | 73efecca42dbc44200e797e02f8c1e24fcff26ef (patch) | |
| tree | 46969fed9d5c09a4164257dace56a71cad9092ab /05_callback/worker.mjs | |
| parent | 2a8e7aeeef99161b6f0378ac14e297c23ca6227b (diff) | |
| download | emscripten-tutorial-73efecca42dbc44200e797e02f8c1e24fcff26ef.tar.gz emscripten-tutorial-73efecca42dbc44200e797e02f8c1e24fcff26ef.zip | |
Added two more examples
Diffstat (limited to '05_callback/worker.mjs')
| -rw-r--r-- | 05_callback/worker.mjs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/05_callback/worker.mjs b/05_callback/worker.mjs new file mode 100644 index 0000000..736e9f8 --- /dev/null +++ b/05_callback/worker.mjs | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | import Primes from "./build/primes.mjs"; | ||
| 2 | |||
| 3 | var primes = await Primes(); | ||
| 4 | const logPtr = primes.addFunction((cstr) => { | ||
| 5 | postMessage({ message: primes.UTF8ToString(cstr) }); | ||
| 6 | }, "vp"); | ||
| 7 | |||
| 8 | onmessage = (e) => { | ||
| 9 | const count = primes._primes_in_range(e.data.a, e.data.b, logPtr); | ||
| 10 | postMessage({ message: "There are " + count + " primes between " + | ||
| 11 | e.data.a + " and " + e.data.b }); | ||
| 12 | }; | ||
