| 62 | } |
| 63 | |
| 64 | async close(): Promise<void> { |
| 65 | // Remove our event listeners first |
| 66 | this._stdin.off('data', this._ondata); |
| 67 | this._stdin.off('error', this._onerror); |
| 68 | |
| 69 | // Check if we were the only data listener |
| 70 | const remainingDataListeners = this._stdin.listenerCount('data'); |
| 71 | if (remainingDataListeners === 0) { |
| 72 | // Only pause stdin if we were the only listener |
| 73 | // This prevents interfering with other parts of the application that might be using stdin |
| 74 | this._stdin.pause(); |
| 75 | } |
| 76 | |
| 77 | // Clear the buffer and notify closure |
| 78 | this._readBuffer.clear(); |
| 79 | this.onclose?.(); |
| 80 | } |
| 81 | |
| 82 | send(message: JSONRPCMessage): Promise<void> { |
| 83 | return new Promise(resolve => { |