import { workerCode } from './worker.inline';
const blob = new Blob([workerCode], { type: 'text/javascript' });
const url = URL.createObjectURL(blob);
const worker = new Worker(url);
let requestId = 0;
const pending = new Map();
worker.addEventListener('message', (event) => {
    const { id, ...rest } = event.data;
    const promise = pending.get(id);
    if (!promise) {
        return;
    }
    pending.delete(id);
    if ('error' in rest) {
        promise.reject(rest.error);
    }
    else {
        promise.resolve(rest);
    }
});
export const parsePcdInWorker = (data) => {
    return new Promise((resolve, reject) => {
        const id = ++requestId;
        pending.set(id, { resolve, reject });
        const copy = new Uint8Array(data);
        worker.postMessage({ id, data: copy }, [copy.buffer]);
    });
};
