*Dont call init in constructor
*Rename init to run *Make run a chained method and not async
This commit is contained in:
parent
b5bb0c1889
commit
00ccbc9536
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 = [];
|
||||
|
||||
for (const relay of this.getRelays()) {
|
||||
promises.push(this.queryRelay(relay));
|
||||
}
|
||||
|
||||
await Promise.allSettled(promises);
|
||||
this.checkResponses();
|
||||
Promise.allSettled(promises).then(() => this.checkResponses());
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
protected async queryRelay(relay: string | Buffer): Promise<any> {
|
||||
|
|
|
@ -69,7 +69,7 @@ export default class WisdomRpcQuery extends RpcQueryBase {
|
|||
return;
|
||||
}
|
||||
|
||||
this.init();
|
||||
this.run();
|
||||
}
|
||||
|
||||
protected getRelays(): string[] | [] {
|
||||
|
|
Loading…
Reference in New Issue