diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2024-05-03 16:21:32 -0300 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2024-05-31 12:11:48 -0300 |
commit | 8190bf63ea9ae0c4f71c72e5818ce5197ec49113 (patch) | |
tree | 0cdd3efff13e35aecd53ba1aa81874f51dfa894c /src | |
parent | 94b9895a5a0d836f9e91ef87779ac29a1b2c525f (diff) |
client: report errors setting up search worker
Diffstat (limited to 'src')
-rw-r--r-- | src/static/js/client.js | 27 | ||||
-rw-r--r-- | src/static/js/search-worker.js | 4 |
2 files changed, 20 insertions, 11 deletions
diff --git a/src/static/js/client.js b/src/static/js/client.js index 678e3444..e570b91a 100644 --- a/src/static/js/client.js +++ b/src/static/js/client.js @@ -3433,10 +3433,10 @@ const wikiSearchInfo = initInfo('wikiSearchInfo', { worker: null, workerReadyPromise: null, - resolveWorkerReadyPromise: null, + workerReadyPromiseResolvers: null, workerActionCounter: 0, - workerActionPromiseMap: new Map(), + workerActionPromiseResolverMap: new Map(), }, }); @@ -3454,11 +3454,11 @@ async function initializeSearchWorker() { state.worker.onmessage = handleSearchWorkerMessage; - ({promise: state.workerReadyPromise, - resolve: state.resolveWorkerReadyPromise} = - promiseWithResolvers()); + const {promise, resolve, reject} = promiseWithResolvers(); + + state.workerReadyPromiseResolvers = {resolve, reject}; - return await state.workerReadyPromise; + return await (state.workerReadyPromise = promise); } function handleSearchWorkerMessage(message) { @@ -3487,7 +3487,12 @@ function handleSearchWorkerStatusMessage(message) { case 'ready': console.debug(`Search worker has loaded corpuses and is ready.`); - state.resolveWorkerReadyPromise(state.worker); + state.workerReadyPromiseResolvers.resolve(state.worker); + break; + + case 'setup-error': + console.debug(`Search worker failed to initialize.`); + state.workerReadyPromiseResolvers.reject('setup-error'); break; default: @@ -3505,13 +3510,13 @@ function handleSearchWorkerResultMessage(message) { return; } - if (!state.workerActionPromiseMap.has(id)) { + if (!state.workerActionPromiseResolverMap.has(id)) { console.warn(`Runaway result id <- from search worker:`, message.data); return; } const {resolve, reject} = - state.workerActionPromiseMap.get(id); + state.workerActionPromiseResolverMap.get(id); switch (message.data.status) { case 'resolve': @@ -3527,7 +3532,7 @@ function handleSearchWorkerResultMessage(message) { return; } - state.workerActionPromiseMap.delete(id); + state.workerActionPromiseResolverMap.delete(id); } async function postSearchWorkerAction(action, options) { @@ -3538,7 +3543,7 @@ async function postSearchWorkerAction(action, options) { const {promise, resolve, reject} = promiseWithResolvers(); - state.workerActionPromiseMap.set(id, {resolve, reject}); + state.workerActionPromiseResolverMap.set(id, {resolve, reject}); worker.postMessage({ kind: 'action', diff --git a/src/static/js/search-worker.js b/src/static/js/search-worker.js index 24412b22..166be2a2 100644 --- a/src/static/js/search-worker.js +++ b/src/static/js/search-worker.js @@ -13,6 +13,10 @@ postStatus('alive'); main().then( () => { postStatus('ready'); + }, + error => { + console.error(`Search worker setup error:`, error); + postStatus('setup-error'); }); async function main() { |