Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 3 additions & 14 deletions web/src/engine/predictive-text/worker-thread/src/main/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,16 @@ export default class LMLayerWorker {
}
}

private loadModelFile(url: string, tryCount: number = 0) {
private loadModelFile(url: string) {
// The self/global WebWorker method, allowing us to directly import another script file into WebWorker scope.
// If built correctly, the model's script file will auto-register the model with loadModel() above.
try {
this._importScripts(url);
} catch (err) {
// Does not catch errors thrown within the imported script.
// Does catch errors with the model script's file-path.
// #13862: attempt to mitigate NetworkError on Chrome by retrying before giving up
tryCount++;
if(err instanceof Error && err.name == 'NetworkError') {
if(tryCount < 4) {
// increase delay with each retry: 10msec, 100msec, 1000msec
console?.warn(`NetworkError when attempting to load dictionary (attempt ${tryCount} of 4, will retry after ${10 ** tryCount} msec): ${err.toString()}`);
setTimeout(() => this.loadModelFile(url, tryCount), 10 ** tryCount);
} else {
this.error(`NetworkError when attempting to load dictionary (attempt ${tryCount} of 4, giving up): ${err.toString()}`);
}
} else {
this.error("Error occurred when attempting to load dictionary", err);
}
this.error("Error occurred when attempting to load dictionary", err);

// Remain in the model-unloaded state; the load attempt was unsuccessful.
}
}
Expand Down
Loading