add assertion on trustedPromise !== null

This commit is contained in:
Michael Peters 2022-10-19 22:02:17 -07:00
parent cdc3307cb2
commit 5df8948886

View File

@ -6,6 +6,7 @@ const LOG = Logger.create(__filename, electronConsole);
import { Changes, WithEquals } from './data-types';
import * as uuid from 'uuid';
import assert from 'assert';
export enum AutoVerifierChangesType {
NONE, // both primaryFunc and trustedFunc returned null
@ -217,8 +218,7 @@ export class AutoVerifier<T> {
}
const tryResolveTrustedPromise = async () => {
if (this.trustedPromise) {
// there is a trusted promise that we can check
assert(this.trustedPromise !== null)
if (this.trustedStatus === 'fetching') {
// no one has started verifying the trusted yet
@ -226,7 +226,7 @@ export class AutoVerifier<T> {
this.trustedStatus = 'verifying';
// note: Promises that have already resolved will return the same value when awaited again :)
const origTrustedPromise: Promise<T | null> | null = this.trustedPromise;
const origTrustedPromise: Promise<T | null> = this.trustedPromise;
let trustedResult = undefined;
try {
trustedResult = await origTrustedPromise;
@ -335,13 +335,6 @@ export class AutoVerifier<T> {
resolved = true;
}
}
} else {
// we are all up to date, make sure to resolve if primaryResult is null
if (!resolved) {
resolve(null);
resolved = true;
}
}
};
await tryResolveTrustedPromise();
} catch (e: unknown) {