summaryrefslogtreecommitdiff
path: root/tests/testdata/workers/worker_doest_stall_event_loop.ts
blob: bfddee2eca16a04fa133d02fffd3344d357539b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const moduleCode = `
console.log('module start');
const hash = await crypto.subtle.digest('SHA-1', new TextEncoder().encode('data'));
const __default = {};
export { __default as default };
console.log('module finish');
`;

const workerCode = `
    console.log('worker!');

    globalThis.onmessage = (msg) => {
        const { moduleCode } = msg.data;
        (async () => {
            console.log('before import');
            await import(URL.createObjectURL(new Blob([ moduleCode ])));
            console.log('after import');
            self.postMessage('thanks');
        })();
    }
`;
const worker = new Worker(URL.createObjectURL(new Blob([workerCode])), {
  type: "module",
});
worker.onmessage = () => {
  console.log("worker.terminate");
  worker.terminate();
};
worker.postMessage({ moduleCode });