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
* are remaining.
*/
static #destroyEngine({ id, keyName }) {
static async #destroyEngine({ id, keyName }) {
ChromeUtils.addProfilerMarker(
"EngineProcess",
{},
`Destroying the "${id}" engine`
);
const actorShutdown = this.forceActorShutdown(id, keyName).catch(
error => void console.error(error)
);
let actorShutdown = this.forceActorShutdown(id, keyName);
this[keyName] = null;
@ -355,7 +353,7 @@ export class EngineProcess {
EngineProcess.#hiddenFrame = null;
// 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
// shutdown.
if (this.translationsEngineParent && this.mlEngineParent) {
@ -373,8 +371,12 @@ export class EngineProcess {
});
}
// Infallibly resolve the promise even if there are errors.
return Promise.resolve();
// Infallibly resolve this promise even if there are errors.
try {
await actorShutdown;
} catch (error) {
console.error(error);
}
}
/**