blob: 9ae7ee83e2e9a0c1de173e1fee7b82a7144eaa54 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
export type TestResult = {
error: String | undefined;
};
export async function launchWorker() {
const selfPath = import.meta.url;
const selfPathDir = selfPath.substring(0, selfPath.lastIndexOf('/'));
const workerPath = selfPathDir + '/worker.js';
const worker = new Worker(workerPath, { type: 'module' });
const promise = new Promise<TestResult>(resolve => {
worker.addEventListener('message', ev => resolve(ev.data as TestResult), { once: true });
});
worker.postMessage({});
return await promise;
}
|