*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,
|
bypassCache: bypassCache || this._bypassCache,
|
||||||
},
|
},
|
||||||
options
|
options
|
||||||
);
|
).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public streamingQuery(
|
public streamingQuery(
|
||||||
|
@ -123,7 +123,7 @@ export default class RpcNetwork {
|
||||||
relay,
|
relay,
|
||||||
{ method, module, data },
|
{ method, module, data },
|
||||||
{ streamHandler, ...options }
|
{ streamHandler, ...options }
|
||||||
);
|
).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
public simpleQuery(
|
public simpleQuery(
|
||||||
|
@ -142,6 +142,6 @@ export default class RpcNetwork {
|
||||||
data,
|
data,
|
||||||
},
|
},
|
||||||
options
|
options
|
||||||
);
|
).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,6 @@ export default abstract class RpcQueryBase {
|
||||||
this._network = network;
|
this._network = network;
|
||||||
this._query = query;
|
this._query = query;
|
||||||
this._options = options;
|
this._options = options;
|
||||||
this.init();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get result(): Promise<RPCResponse> {
|
get result(): Promise<RPCResponse> {
|
||||||
|
@ -52,7 +51,7 @@ export default abstract class RpcQueryBase {
|
||||||
this._promiseResolve?.(data);
|
this._promiseResolve?.(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async init() {
|
public run(): this {
|
||||||
this._promise =
|
this._promise =
|
||||||
this._promise ??
|
this._promise ??
|
||||||
new Promise<any>((resolve) => {
|
new Promise<any>((resolve) => {
|
||||||
|
@ -66,16 +65,17 @@ export default abstract class RpcQueryBase {
|
||||||
(this._options.queryTimeout || this._network.queryTimeout) * 1000
|
(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()) {
|
for (const relay of this.getRelays()) {
|
||||||
promises.push(this.queryRelay(relay));
|
promises.push(this.queryRelay(relay));
|
||||||
}
|
}
|
||||||
|
|
||||||
await Promise.allSettled(promises);
|
Promise.allSettled(promises).then(() => this.checkResponses());
|
||||||
this.checkResponses();
|
});
|
||||||
|
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async queryRelay(relay: string | Buffer): Promise<any> {
|
protected async queryRelay(relay: string | Buffer): Promise<any> {
|
||||||
|
|
|
@ -69,7 +69,7 @@ export default class WisdomRpcQuery extends RpcQueryBase {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.init();
|
this.run();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected getRelays(): string[] | [] {
|
protected getRelays(): string[] | [] {
|
||||||
|
|
Loading…
Reference in New Issue