aboutsummaryrefslogtreecommitdiff
path: root/05_callback/worker.mjs
blob: b78d3662e862bc74b8edac3dd43a67e50d61d9a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import Primes from "./build/primes.mjs";

var primes = await Primes();
const logPtr = primes.addFunction((cstr) => {
	const str = primes.UTF8ToString(cstr);

	console.log(str);
	postMessage({ message: str });
}, "vp");

onmessage = (e) => {
	const count = primes._primes_in_range(e.data.a, e.data.b, logPtr);
	postMessage({ message: "There are " + count + " primes between " +
		e.data.a + " and " + e.data.b });
};

Generated with cgit - Back to sebastiano.tronto.net