Added destroy to WebSocketProvider.
This commit is contained in:
parent
c6601769ad
commit
d0a79c6a13
@ -274,4 +274,22 @@ export class WebSocketProvider extends JsonRpcProvider {
|
||||
this.send("eth_unsubscribe", [ subId ]);
|
||||
});
|
||||
}
|
||||
|
||||
async destroy(): Promise<void> {
|
||||
// Wait until we have connected before trying to disconnect
|
||||
if (this._websocket.readyState === WebSocket.CONNECTING) {
|
||||
await new Promise((resolve) => {
|
||||
this._websocket.on("open", () => {
|
||||
resolve(true);
|
||||
});
|
||||
|
||||
this._websocket.on("error", () => {
|
||||
resolve(false);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Hangup (navigating away from the page that opened the connection)
|
||||
this._websocket.close(1001);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user