*Need to use dynamic import
ci/woodpecker/push/woodpecker Pipeline was successful
Details
ci/woodpecker/push/woodpecker Pipeline was successful
Details
This commit is contained in:
parent
324106d54f
commit
6413d97c61
|
@ -11,13 +11,30 @@ import {
|
||||||
import { getRpcByPeer } from "../rpc";
|
import { getRpcByPeer } from "../rpc";
|
||||||
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
|
import { get as getSwarm, LUMEWEB_TOPIC_HASH } from "../swarm";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import pTimeout, { ClearablePromise } from "p-timeout";
|
|
||||||
|
import type { ClearablePromise } from "p-timeout";
|
||||||
|
|
||||||
|
async function dImport(pkg: string): Promise<any> {
|
||||||
|
return new Function(`return import("${pkg}")`);
|
||||||
|
}
|
||||||
|
|
||||||
|
let pTimeout: typeof import("p-timeout").default;
|
||||||
|
const pTimeoutImport = dImport(
|
||||||
|
"p-timeout"
|
||||||
|
) as unknown as typeof import("p-timeout");
|
||||||
|
|
||||||
|
async function importSetup() {
|
||||||
|
if (!pTimeout) {
|
||||||
|
pTimeout = (await pTimeoutImport).default;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
async function broadcastRequest(
|
async function broadcastRequest(
|
||||||
request: RPCRequest,
|
request: RPCRequest,
|
||||||
relays: string[],
|
relays: string[],
|
||||||
timeout = 5000
|
timeout = 5000
|
||||||
): Promise<Map<string, Promise<any>>> {
|
): Promise<Map<string, Promise<any>>> {
|
||||||
|
await importSetup();
|
||||||
const makeRequest = async (relay: string) => {
|
const makeRequest = async (relay: string) => {
|
||||||
const rpc = await getRpcByPeer(relay);
|
const rpc = await getRpcByPeer(relay);
|
||||||
return rpc.request(`${request.module}.${request.method}`, request.data);
|
return rpc.request(`${request.module}.${request.method}`, request.data);
|
||||||
|
|
Loading…
Reference in New Issue