*Add ready method

This commit is contained in:
Derrick Hammer 2022-08-14 06:54:18 -04:00
parent ac9cc4cf0d
commit 47dc0be026
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 33 additions and 20 deletions

View File

@ -1,18 +1,17 @@
const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A"; const DNS_MODULE = "AQBLKpieqOfKVRgMa8k45P4S_ILYgJmswVso4vT1qzoG-A";
let callModule: any, let callModule: any, connectModule: any;
connectModule: any;
async function loadLibs() { async function loadLibs() {
if (callModule && connectModule) { if (callModule && connectModule) {
return; return;
} }
if (typeof window !== "undefined" && window?.document) { if (typeof window !== "undefined" && window?.document) {
const pkg = (await import("libkernel")); const pkg = await import("libkernel");
callModule = pkg.callModule; callModule = pkg.callModule;
connectModule = pkg.connectModule; connectModule = pkg.connectModule;
} else { } else {
const pkg = (await import("libkmodule")); const pkg = await import("libkmodule");
callModule = pkg.callModule; callModule = pkg.callModule;
connectModule = pkg.connectModule; connectModule = pkg.connectModule;
} }
@ -20,7 +19,21 @@ async function loadLibs() {
export async function resolve(domain: string, params: any, force = false) { export async function resolve(domain: string, params: any, force = false) {
await loadLibs(); await loadLibs();
const [resp, err] = await callModule(DNS_MODULE, "resolve", {domain, params, force}); const [resp, err] = await callModule(DNS_MODULE, "resolve", {
domain,
params,
force,
});
if (err) {
throw new Error(err);
}
return resp;
}
export async function ready() {
await loadLibs();
const [resp, err] = await callModule(DNS_MODULE, "ready");
if (err) { if (err) {
throw new Error(err); throw new Error(err);