*Lazy load dht ready promise

This commit is contained in:
Derrick Hammer 2022-07-26 20:58:41 -04:00
parent efa8b50463
commit d3d94c7162
1 changed files with 3 additions and 1 deletions

View File

@ -5,7 +5,6 @@ import DHT from "@hyperswarm/dht";
export default class RpcNetwork { export default class RpcNetwork {
constructor(dht = new DHT()) { constructor(dht = new DHT()) {
this._dht = dht; this._dht = dht;
this._ready = this._dht.ready();
} }
private _dht: typeof DHT; private _dht: typeof DHT;
@ -63,6 +62,9 @@ export default class RpcNetwork {
private _ready: Promise<void>; private _ready: Promise<void>;
get ready(): Promise<void> { get ready(): Promise<void> {
if (!this._ready) {
this._ready = this._dht.ready();
}
return this._ready; return this._ready;
} }