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:
parent
02d1027c05
commit
51053bc6d9
|
@ -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 {
|
||||
|
|
22
src/vars.ts
22
src/vars.ts
|
@ -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();
|
||||
}
|
||||
|
|
Reference in New Issue