feat: init

This commit is contained in:
Morten Olsen
2023-09-06 10:56:36 +02:00
commit bfa26fbfb1
55 changed files with 6076 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
type WorkerFn = Record<string, (...args: any[]) => any>;
const createWorker = (fn: WorkerFn) => {
self.addEventListener('message', (event) => {
const { action, vars = {}, id } = event.data;
const run = async () => {
const startTime = performance.now();
try {
const result = await fn[action](vars);
const endTime = performance.now();
const duration = endTime - startTime;
self.postMessage({ type: 'output', payload: result, id, duration });
} catch (error) {
self.postMessage({ type: 'error', payload: error, id });
}
};
run();
});
};
export { createWorker };