Skip to content

Commit

Permalink
fix unhandled promise rejections
Browse files Browse the repository at this point in the history
  • Loading branch information
Eisenwave committed Aug 10, 2023
1 parent 598c7a1 commit 73aaad2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 9 deletions.
7 changes: 5 additions & 2 deletions indexes/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,10 @@ export class ThreadPool<JobType, ResultType> implements AsyncIterable<ResultType
}
private create_new_worker(worker_path: string) {
const worker = new Worker(worker_path);
worker.on("message", message => this.handle_worker_message(worker, message));
worker.on("message", message => {
this.handle_worker_message(worker, message)
.catch(console.error);
});
return worker;
}
private async handle_worker_message(worker: Worker, message: MessageForThreadPool<ResultType>) {
Expand Down Expand Up @@ -144,7 +147,7 @@ export class Funnel {
await promise_factory();
this.count--;
this.on_promise_finish();
})();
})().catch(console.error);
}
private on_promise_finish() {
// run the next promise if needed
Expand Down
4 changes: 2 additions & 2 deletions indexes/cppref/create_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ async function* walk_dir(dir: string): AsyncGenerator<string> {
}
}

(async () => {
await (async () => {
let index: cppref_index = {
c: [],
cpp: []
Expand All @@ -38,7 +38,7 @@ async function* walk_dir(dir: string): AsyncGenerator<string> {

let count = 0;

(async () => {
await (async () => {
console.log("en.cppreference.com/w/c");
for await(const path of walk_dir("en.cppreference.com/w/c")) {
if(path.endsWith(".html")) {
Expand Down
6 changes: 4 additions & 2 deletions indexes/cppref/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,10 @@ async function handle_worker_message(message: MessageForWorker<WorkerJob>):
};
}

parentPort.on("message", async (message: MessageForWorker<WorkerJob>) => {
parentPort!.postMessage(await handle_worker_message(message));
parentPort.on("message", (message: MessageForWorker<WorkerJob>) => {
handle_worker_message(message)
.then(m => parentPort!.postMessage(m))
.catch(console.error);
});

parentPort.on("close", () => {
Expand Down
2 changes: 1 addition & 1 deletion indexes/man7/create_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { man7_index, WorkerJob, WorkerResponse } from "./types";
const seed_url = "https://man7.org/linux/man-pages/dir_all_by_section.html";
const base_url = "https://man7.org/linux/man-pages/";

(async () => {
await (async () => {
let man_entries: man7_index = [];
if(fs.existsSync("man7_index.json")) {
man_entries = JSON.parse(await fs.promises.readFile("man7_index.json", { encoding: "utf-8" }));
Expand Down
6 changes: 4 additions & 2 deletions indexes/man7/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,10 @@ async function handle_worker_message(message: MessageForWorker<WorkerJob>):
};
}

parentPort.on("message", async (message: MessageForWorker<WorkerJob>) => {
parentPort!.postMessage(await handle_worker_message(message));
parentPort.on("message", (message: MessageForWorker<WorkerJob>) => {
handle_worker_message(message)
.then(m => parentPort!.postMessage(m))
.catch(console.error);
});

parentPort.on("close", () => {
Expand Down

0 comments on commit 73aaad2

Please sign in to comment.