diff --git a/src/model/Api/indexi.ts b/src/model/Api/indexi.ts index 6248d866..ace98edf 100644 --- a/src/model/Api/indexi.ts +++ b/src/model/Api/indexi.ts @@ -138,4 +138,22 @@ export class Api { } return 'error' as EventStatus; }; + + // ------------------------------------------------------ + // Disconnect + // ------------------------------------------------------ + + // Remove API event listeners if they exist. + unsubscribeProvider() { + this.#providerUnsubs.forEach((unsub) => { + unsub(); + }); + } + + // Disconnect gracefully from API and provider. + async disconnect() { + this.unsubscribeProvider(); + this.provider?.disconnect(); + await this.api?.disconnect(); + } }