Skip to content

Commit

Permalink
fix exception handle bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Dec 12, 2024
1 parent 9b69113 commit 7f7b7da
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
8 changes: 6 additions & 2 deletions light-client-js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@ class LightClient {
this.lightClientWorker.removeEventListener("message", resolveFn);
this.lightClientWorker.removeEventListener("error", errorFn);
}
const resolveFn = (evt: MessageEvent<any>) => {
resolve(evt.data);
const resolveFn = (evt: MessageEvent<{ ok: true; data: any } | { ok: false; error: string; }>) => {
if (evt.data.ok === true) {
resolve(evt.data.data);
} else {
reject(evt.data.error);
}
clean();

};
Expand Down
13 changes: 12 additions & 1 deletion light-client-js/src/lightclient.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,18 @@ onmessage = async (evt) => {
return;
}
const data = evt.data as LightClientFunctionCall;
self.postMessage(((wasmModule as any)[data.name])(...evt.data.args))
try {
self.postMessage({
ok: true,
data: ((wasmModule as any)[data.name])(...evt.data.args)
})
} catch (e) {
self.postMessage({
ok: false,
error: `${e}`
})
console.error(e);
}
};

export { };

0 comments on commit 7f7b7da

Please sign in to comment.