async close()

in lib/eventstream_rpc.ts [524:560]


    async close() : Promise<void> {
        return new Promise<void>(async (resolve, reject) => {
            try {
                if (this.state == ClientState.Closed) {
                    resolve();
                    return;
                }

                this.state = ClientState.Closed;

                if (this.emitDisconnectOnClose) {
                    this.emitDisconnectOnClose = false;
                    if (!this.disconnectionReason) {
                        this.disconnectionReason = new CrtError("User-initiated disconnect");
                    }

                    setImmediate(() => {
                        this.emit('disconnection', {reason: this.disconnectionReason});
                    });
                }

                if (this.unclosedOperations) {
                    let unclosedOperations: Set<OperationBase> = this.unclosedOperations;
                    this.unclosedOperations = undefined;

                    for (const operation of unclosedOperations) {
                        await operation.close();
                    }
                }

                this.connection.close();
                resolve();
            } catch (err) {
                reject(err);
            }
        });
    }