*Switch to using maybeGetAsyncProperty
This commit is contained in:
parent
5e4617ac55
commit
bb36a80913
|
@ -2,7 +2,7 @@
|
||||||
import Hyperswarm from "hyperswarm";
|
import Hyperswarm from "hyperswarm";
|
||||||
import RpcNetworkQueryFactory from "./query/index.js";
|
import RpcNetworkQueryFactory from "./query/index.js";
|
||||||
import b4a from "b4a";
|
import b4a from "b4a";
|
||||||
import { createHash, isPromise } from "./util.js";
|
import { createHash, maybeGetAsyncProperty } from "./util.js";
|
||||||
|
|
||||||
export default class RpcNetwork {
|
export default class RpcNetwork {
|
||||||
private _relaysAvailablePromise?: Promise<void>;
|
private _relaysAvailablePromise?: Promise<void>;
|
||||||
|
@ -70,15 +70,9 @@ export default class RpcNetwork {
|
||||||
|
|
||||||
get ready(): Promise<void> {
|
get ready(): Promise<void> {
|
||||||
if (!this._ready) {
|
if (!this._ready) {
|
||||||
let dht = this._swarm.dht;
|
this._ready = maybeGetAsyncProperty(this._swarm.dht).then((dht: any) =>
|
||||||
if (typeof dht === "function") {
|
dht.ready()
|
||||||
dht = dht();
|
) as Promise<void>;
|
||||||
}
|
|
||||||
if (isPromise(dht)) {
|
|
||||||
this._ready = dht.then((dht: any) => dht.ready());
|
|
||||||
} else {
|
|
||||||
this._ready = this._swarm.dht.ready() as Promise<void>;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this._ready as Promise<void>;
|
return this._ready as Promise<void>;
|
||||||
|
|
Loading…
Reference in New Issue