From bafd0dac831e4d56bafee212a0d61dfd689a9b4b Mon Sep 17 00:00:00 2001 From: Oliver Blanthorn Date: Mon, 15 Feb 2021 09:55:09 +0100 Subject: [PATCH] Use short-lived cache for :native --- src/lib/native.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/native.ts b/src/lib/native.ts index d4943f8f..5b96cbe8 100644 --- a/src/lib/native.ts +++ b/src/lib/native.ts @@ -88,9 +88,13 @@ export async function getrc(): Promise { } } +let NATIVE_VERSION_CACHE: string export async function getNativeMessengerVersion( quiet = false, ): Promise { + if (NATIVE_VERSION_CACHE !== undefined) { + return NATIVE_VERSION_CACHE + } const res = await sendNativeMsg("version", {}, quiet) if (res === undefined) { if (quiet) return undefined @@ -98,7 +102,10 @@ export async function getNativeMessengerVersion( } if (res.version && !res.error) { logger.info(`Native version: ${res.version}`) - return res.version.toString() + NATIVE_VERSION_CACHE = res.version.toString() + // Wipe cache after 500ms + setTimeout(() => (NATIVE_VERSION_CACHE = undefined), 500) + return NATIVE_VERSION_CACHE } }