Skip to content

Commit

Permalink
dispose method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dojyorin committed Jan 20, 2024
1 parent 8e9cd6b commit ecdf62c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,24 @@ export function createTask<T extends unknown, K extends unknown>(task:TaskAction
type: "module"
});

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

worker.onmessage = ({data})=>{
res(data);
dispose();
};

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

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

worker.postMessage(message, {
Expand Down

0 comments on commit ecdf62c

Please sign in to comment.