* Sends the request using the active connection. * @private
()
| 145 | * @private |
| 146 | */ |
| 147 | _sendOnConnection() { |
| 148 | this._startTime = process.hrtime(); |
| 149 | |
| 150 | this._operation = |
| 151 | this._connection.sendStream(this._request, this._parent.executionOptions, (err, response, length) => { |
| 152 | const errorCode = RequestExecution._getErrorCode(err); |
| 153 | |
| 154 | this._trackResponse(process.hrtime(this._startTime), errorCode, err, length); |
| 155 | |
| 156 | if (this._cancelled) { |
| 157 | // Avoid handling the response / err |
| 158 | return; |
| 159 | } |
| 160 | |
| 161 | if (errorCode !== errorCodes.none) { |
| 162 | return this._handleError(errorCode, err); |
| 163 | } |
| 164 | |
| 165 | if (response.schemaChange) { |
| 166 | return promiseUtils.toBackground( |
| 167 | this._parent.client |
| 168 | .handleSchemaAgreementAndRefresh(this._connection, response.schemaChange) |
| 169 | .then(agreement => { |
| 170 | if (this._cancelled) { |
| 171 | // After the schema agreement method was started, this execution was cancelled |
| 172 | return; |
| 173 | } |
| 174 | |
| 175 | this._parent.setCompleted(null, this._getResultSet(response, agreement)); |
| 176 | }) |
| 177 | ); |
| 178 | } |
| 179 | |
| 180 | if (response.keyspaceSet) { |
| 181 | this._parent.client.keyspace = response.keyspaceSet; |
| 182 | } |
| 183 | |
| 184 | if (response.meta && response.meta.newResultId && this._request.queryId) { |
| 185 | // Update the resultId on the existing prepared statement. |
| 186 | // Eventually would want to update the result metadata as well (NODEJS-433) |
| 187 | const info = this._parent.client.metadata.getPreparedById(this._request.queryId); |
| 188 | info.meta.resultId = response.meta.newResultId; |
| 189 | } |
| 190 | |
| 191 | this._parent.setCompleted(null, this._getResultSet(response)); |
| 192 | }); |
| 193 | } |
| 194 | |
| 195 | _trackResponse(latency, errorCode, err, length) { |
| 196 | // Record metrics |
no test coverage detected