Skip to content

Commit

Permalink
fix: restart worker if an error occured
Browse files Browse the repository at this point in the history
  • Loading branch information
TheNoim committed Jan 24, 2023
1 parent b77af9e commit f21b15a
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions reactive_home/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,29 @@ for await (const path of walk(flags.root)) {

console.info("Load script", path.path);

new Worker(new URL(join(Deno.cwd(), path.path), import.meta.url).href, {
type: "module",
});
const loadWorker = async () => {
while (true) {
const worker = new Worker(
new URL(join(Deno.cwd(), path.path), import.meta.url).href,
{
type: "module",
}
);

await new Promise((resolve) => {
worker.onerror = (error) => {
console.error(
`Terminate worker ${path.path} because of an error. Restart in 5s.`,
error
);
worker.terminate();
setTimeout(() => {
resolve(null);
}, 5 * 1000);
};
});
}
};

loadWorker();
}

0 comments on commit f21b15a

Please sign in to comment.