refactor: change name of booted promise api, add a boot store, and tag onto the promise to flag the new booted property

This commit is contained in:
Derrick Hammer 2023-07-31 12:52:06 -04:00
parent 02d1027c05
commit 51053bc6d9
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 20 additions and 8 deletions

View File

@ -2,7 +2,7 @@ import NodeCache from "node-cache";
import { DNS_RECORD_TYPE } from "@lumeweb/libresolver";
import type { DNSResult, ResolverOptions } from "@lumeweb/libresolver";
import { bufToHex } from "@lumeweb/libweb";
import { getDnsSetupDefer } from "./vars.js";
import { getBooted } from "./vars.js";
import { dnsClient } from "./clients.js";
import { blake3 } from "@noble/hashes/blake3";
@ -20,7 +20,9 @@ export async function resolve(
return cache.get(cacheId) as DNSResult;
}
await getDnsSetupDefer().promise;
if (!getBooted()) {
return resolverEmptyResponse();
}
let res;
try {

View File

@ -14,9 +14,13 @@ let authStatus: KernelAuthStatus;
let authStatusKnown = false;
let authStatusDefer = defer();
let kernelFrame: HTMLIFrameElement;
let blockForDnsSetup = defer();
let loggedInDefer = defer();
let booted = defer();
let booted = false;
let bootedDefer = defer();
bootedDefer.promise.then(() => {
booted = true;
});
export const events = new Emittery();
export function getAuthStatusKnown() {
@ -113,14 +117,20 @@ export function getLoggedInDefer() {
export function resetLoggedInDefer() {
loggedInDefer = defer();
}
export function getBooted(): Promise<unknown> {
return booted.promise;
export function awaitBooted(): Promise<unknown> {
return bootedDefer.promise;
}
export function getBooted() {
return booted;
}
export function resetBooted(): void {
booted = defer();
bootedDefer = defer();
bootedDefer.promise.then(() => {
booted = true;
});
}
export function weAreBooted(): void {
booted.resolve();
bootedDefer.resolve();
}