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