Bunadvanced
Parallel work with Bun's Worker
export const countPrimesOnWorker = (from: number, to: number) => {
const workerCode = `
self.onmessage = ({ data: [from, to] }) => {
let count = 0;
for (let n = from; n < to; n++) {Bun's Worker API uses real OS threads, so CPU-bound work can be split across workers created from an in-memory blob: URL, with no separate worker file needed.