From bd517977c0607788b3a9ea9ecb23481a6b6422f0 Mon Sep 17 00:00:00 2001 From: vdang Date: Wed, 15 Mar 2023 00:25:05 +0100 Subject: [PATCH] Add new function to initialize Stronghold javascript type to avoid data race --- plugins/stronghold/guest-js/index.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/plugins/stronghold/guest-js/index.ts b/plugins/stronghold/guest-js/index.ts index 3339f87f..91bb1457 100644 --- a/plugins/stronghold/guest-js/index.ts +++ b/plugins/stronghold/guest-js/index.ts @@ -389,15 +389,26 @@ export class Vault extends ProcedureExecutor { export class Stronghold { path: string; + /** + * Private constructor. + * Use `Stronghold.init` to create a Stronghold instance. + * @param path + * @param password + */ + private constructor(path: string) { + this.path = path; + } + /** * Initializes a stronghold. * If the snapshot path located at `path` exists, the password must match. * @param path * @param password */ - constructor(path: string, password: string) { - this.path = path; - void this.reload(password); + static async init(path: string, password: string): Promise { + let stronghold = new Stronghold(path); + await stronghold.reload(password); + return stronghold; } /**