Skip to content

Commit

Permalink
Merge pull request #2177 from threefoldtech/development_tfchain_disco…
Browse files Browse the repository at this point in the history
…nnect

Disconnect tfChain provider
  • Loading branch information
MohamedElmdary authored Feb 19, 2024
2 parents 0ef4b60 + 456b01c commit 5088770
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/tfchain_client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class QueryClient {
}

async newProvider() {
let provider: WsProvider;
try {
await QueryClient.connectingLock.acquireAsync();
if (QueryClient.connections.has(this.url)) {
Expand All @@ -89,12 +90,13 @@ class QueryClient {
}
await this.disconnect();

const provider = new WsProvider(this.url);
provider = new WsProvider(this.url);
this.api = await ApiPromise.create({ provider, throwOnConnect: true });
await this.wait();
QueryClient.connections.set(this.url, { api: this.api, disconnectHandler: this.__disconnectHandler });
this.api.on("disconnected", this.__disconnectHandler);
} catch (e) {
if (provider) provider.disconnect();
const message = `Unable to establish a connection with the chain ${this.url} \n`;
if (e instanceof BaseError) {
e.message = message + e.message;
Expand Down

0 comments on commit 5088770

Please sign in to comment.