Skip to content

Commit

Permalink
Wrap errors to work around webworkers not handling onerror correctly?
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonGross committed Nov 21, 2023
1 parent b5447a2 commit 2d0a173
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
8 changes: 6 additions & 2 deletions fiat-html/fiat_crypto_worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
self.importScripts("fiat_crypto.js");
self.onmessage = function(e) {
const result = synthesize(e.data);
postMessage(result);
try {
const result = synthesize(e.data);
postMessage({result: result});
} catch (err) {
postMessage({error: err});
}
};
4 changes: 2 additions & 2 deletions fiat-html/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,9 @@ document.addEventListener('DOMContentLoaded', function() {
const timeTaken = (endTime - startTime) / 1000;
const now = new Date();
const resultData = {
result: e.data,
result: success ? (e.data.error !== undefined ? e.data.error : e.data.result) : e.data,
time: timeTaken,
success: success,
success: success && e.data !== undefined && e.data.error === undefined,
timestamp: now.toISOString(),
version: SYNTHESIS_CACHE_VERSION,
fiat_crypto_version: fiat_crypto_version,
Expand Down

0 comments on commit 2d0a173

Please sign in to comment.