refactor: switch to using defer

This commit is contained in:
Derrick Hammer 2023-07-31 12:50:06 -04:00
parent d67cbc0a06
commit 3f57f9ec44
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 8 additions and 12 deletions

View File

@ -19,6 +19,7 @@ import type { DNSResult } from "@lumeweb/libresolver";
import { blake3 } from "@noble/hashes/blake3";
import "./contentFilters/index.js";
import defer from "p-defer";
export default class WebEngine {
private contentProviders: BaseProvider[] = [];
@ -270,37 +271,32 @@ export default class WebEngine {
}
let dnsResult: boolean | DNSResult = false;
let resolveRequest: any, rejectRequest: any;
let requestDefer = defer();
let promise = new Promise((resolve, reject) => {
resolveRequest = resolve;
rejectRequest = reject;
});
this.navigations.set(this.getNavigationId(details), promise);
this.navigations.set(this.getNavigationId(details), requestDefer.promise);
if ("kernel.lume" === queriedHost) {
if (!queriedUrl.includes("://")) {
queriedUrl = `http://${queriedUrl}`;
}
rejectRequest(queriedUrl);
requestDefer.reject(queriedUrl);
return;
}
if (!getAuthStatus().loginComplete) {
resolveRequest();
requestDefer.resolve();
return;
}
try {
dnsResult = await scanRecords(queriedHost);
} catch (e) {
resolveRequest();
requestDefer.resolve();
return;
}
if (!dnsResult) {
resolveRequest();
requestDefer.resolve();
return;
}
@ -308,7 +304,7 @@ export default class WebEngine {
queriedUrl = `http://${queriedUrl}`;
}
rejectRequest(queriedUrl);
requestDefer.reject(queriedUrl);
}
private getNavigationId(details: any) {