From: Chris Duncan Date: Mon, 14 Oct 2024 09:43:05 +0000 (-0700) Subject: Session storage operations are synchronous, so wrap them in Promises to at least... X-Git-Tag: v0.0.10~1 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=c253910c5695fe78e92cc3c51d28411fadb91448;p=libnemo.git Session storage operations are synchronous, so wrap them in Promises to at least try and not block other processes. --- diff --git a/src/lib/safe.ts b/src/lib/safe.ts index 7d9ae7b..6a2d3c8 100644 --- a/src/lib/safe.ts +++ b/src/lib/safe.ts @@ -58,7 +58,14 @@ export class Safe { encrypted: buffer.toHex(encrypted), iv: iv.hex } - storage.setItem(name, JSON.stringify(record)) + await new Promise((resolve, reject) => { + try { + storage.setItem(name, JSON.stringify(record)) + resolve() + } catch (err) { + reject(err) + } + }) passkey = '' } catch (err) { throw new Error(ERR_MSG) @@ -79,7 +86,9 @@ export class Safe { return null } - const item = storage.getItem(name) + const item = await new Promise(resolve => { + resolve(storage.getItem(name)) + }) if (item == null) { return null }