From 02cd4983bef91af16ad49a91fa7324f164a3a7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Loi=CC=88c=20Correnson?= <loic.correnson@cea.fr> Date: Wed, 18 May 2022 11:27:54 +0200 Subject: [PATCH] [ivette/states] hold synchronized value --- ivette/src/frama-c/states.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ivette/src/frama-c/states.ts b/ivette/src/frama-c/states.ts index c6b360cc86a..c1568d6d2b8 100644 --- a/ivette/src/frama-c/states.ts +++ b/ivette/src/frama-c/states.ts @@ -284,10 +284,11 @@ class SyncState<A> { } getValue(): A | undefined { - if (!this.upToDate && Server.isRunning()) { + const running = Server.isRunning(); + if (!this.upToDate && running) { this.update(); } - return this.value; + return running ? this.value : undefined; } async setValue(v: A): Promise<void> { @@ -309,18 +310,20 @@ class SyncState<A> { async update(): Promise<void> { try { this.upToDate = true; - this.value = undefined; - this.UPDATE.emit(); if (Server.isRunning()) { const v = await Server.send(this.handler.getter, null); this.value = v; this.UPDATE.emit(); + } else if (this.value !== undefined) { + this.value = undefined; + this.UPDATE.emit(); } } catch (error) { D.error( `Fail to update SyncState '${this.handler.name}'.`, `${error}`, ); + this.value = undefined; this.UPDATE.emit(); } } -- GitLab