Skip to content

Commit

Permalink
revoke url each time.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jan 20, 2024
1 parent 0511c3c commit 8e9cd6b
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,27 +48,30 @@ export function createTask<T extends unknown, K extends unknown>(task:TaskAction
});
};
`;
const url = URL.createObjectURL(new Blob([regist]));

return (message, transfers)=>{
return new Promise<K>((res, rej)=>{
const url = URL.createObjectURL(new Blob([regist]));
const worker = new Worker(url, {
type: "module"
});

worker.onmessage = ({data})=>{
res(data);
worker.terminate();
URL.revokeObjectURL(url);
};

worker.onerror = (e)=>{
rej(e);
worker.terminate();
URL.revokeObjectURL(url);
};

worker.onmessageerror = (e)=>{
rej(e);
worker.terminate();
URL.revokeObjectURL(url);
};

worker.postMessage(message, {
Expand Down

0 comments on commit 8e9cd6b

Please sign in to comment.