(method: string, params?: TReq)
| 106 | protected notifyRequestAfterExit() { } |
| 107 | |
| 108 | protected sendRequest<TReq, TResp>(method: string, params?: TReq): Promise<TResp> { |
| 109 | // Generate an ID for this request so we can match up the response. |
| 110 | const id = this.nextRequestID++; |
| 111 | |
| 112 | return new Promise<TResp>((resolve, reject) => { |
| 113 | if (this.processExited) { |
| 114 | this.notifyRequestAfterExit(); |
| 115 | reject(`Tried to call "${method}" but process has already exited with code ${this.process?.exitCode}`); |
| 116 | return; |
| 117 | } |
| 118 | |
| 119 | // Stash the callbacks so we can call them later. |
| 120 | this.activeRequests[id.toString()] = [resolve, reject, method]; |
| 121 | |
| 122 | const req = this.buildRequest(id, method, params); |
| 123 | const json = this.messagesWrappedInBrackets |
| 124 | ? "[" + JSON.stringify(req) + "]\r\n" |
| 125 | : JSON.stringify(req) + "\r\n"; |
| 126 | this.sendMessage(json); |
| 127 | }); |
| 128 | } |
| 129 | |
| 130 | public cancelAllRequests() { |
| 131 | // TODO(dantup): Consider/test rejecting all active requests? |
nothing calls this directly
no test coverage detected