*Dont call init in constructor

*Rename init to run
*Make run a chained method and not async
This commit is contained in:
Derrick Hammer 2022-08-28 02:26:40 -04:00
parent b5bb0c1889
commit 00ccbc9536
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
3 changed files with 13 additions and 13 deletions

View File

@ -107,7 +107,7 @@ export default class RpcNetwork {
bypassCache: bypassCache || this._bypassCache,
},
options
);
).run();
}
public streamingQuery(
@ -123,7 +123,7 @@ export default class RpcNetwork {
relay,
{ method, module, data },
{ streamHandler, ...options }
);
).run();
}
public simpleQuery(
@ -142,6 +142,6 @@ export default class RpcNetwork {
data,
},
options
);
).run();
}
}

View File

@ -27,7 +27,6 @@ export default abstract class RpcQueryBase {
this._network = network;
this._query = query;
this._options = options;
this.init();
}
get result(): Promise<RPCResponse> {
@ -52,7 +51,7 @@ export default abstract class RpcQueryBase {
this._promiseResolve?.(data);
}
protected async init() {
public run(): this {
this._promise =
this._promise ??
new Promise<any>((resolve) => {
@ -66,16 +65,17 @@ export default abstract class RpcQueryBase {
(this._options.queryTimeout || this._network.queryTimeout) * 1000
);
await this._network.ready;
this._network.ready.then(() => {
const promises = [];
const promises = [];
for (const relay of this.getRelays()) {
promises.push(this.queryRelay(relay));
}
for (const relay of this.getRelays()) {
promises.push(this.queryRelay(relay));
}
Promise.allSettled(promises).then(() => this.checkResponses());
});
await Promise.allSettled(promises);
this.checkResponses();
return this;
}
protected async queryRelay(relay: string | Buffer): Promise<any> {

View File

@ -69,7 +69,7 @@ export default class WisdomRpcQuery extends RpcQueryBase {
return;
}
this.init();
this.run();
}
protected getRelays(): string[] | [] {