Bug 1881865 - Await destroying translations engine r=gregtatum

The functions to force destroy the TranslationsEngine
were previously returning a promise that had the
potential to resolve before the engine was actually
destroyed. This ensures everything is properly awaited.

Differential Revision: https://phabricator.services.mozilla.com/D212310
This commit is contained in:
Erik Nordin 2024-06-04 14:36:20 +00:00
parent a00c9a4e43
commit 2893ff2a72

View file

@ -337,16 +337,14 @@ export class EngineProcess {
* Destroy the specified engine and maybe the entire hidden frame as well if no engines * Destroy the specified engine and maybe the entire hidden frame as well if no engines
* are remaining. * are remaining.
*/ */
static #destroyEngine({ id, keyName }) { static async #destroyEngine({ id, keyName }) {
ChromeUtils.addProfilerMarker( ChromeUtils.addProfilerMarker(
"EngineProcess", "EngineProcess",
{}, {},
`Destroying the "${id}" engine` `Destroying the "${id}" engine`
); );
const actorShutdown = this.forceActorShutdown(id, keyName).catch( let actorShutdown = this.forceActorShutdown(id, keyName);
error => void console.error(error)
);
this[keyName] = null; this[keyName] = null;
@ -355,7 +353,7 @@ export class EngineProcess {
EngineProcess.#hiddenFrame = null; EngineProcess.#hiddenFrame = null;
// Both actors are destroyed, also destroy the hidden frame. // Both actors are destroyed, also destroy the hidden frame.
actorShutdown.then(() => { actorShutdown = actorShutdown.then(() => {
// Double check a race condition that no new actors have been created during // Double check a race condition that no new actors have been created during
// shutdown. // shutdown.
if (this.translationsEngineParent && this.mlEngineParent) { if (this.translationsEngineParent && this.mlEngineParent) {
@ -373,8 +371,12 @@ export class EngineProcess {
}); });
} }
// Infallibly resolve the promise even if there are errors. // Infallibly resolve this promise even if there are errors.
return Promise.resolve(); try {
await actorShutdown;
} catch (error) {
console.error(error);
}
} }
/** /**