diff --git a/ivette/src/frama-c/states.ts b/ivette/src/frama-c/states.ts index c6b360cc86ad95daece6e8e54982d07c21570a05..c1568d6d2b834681272951ccda5d6438d9255d63 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(); } }