* Queues the operation to be written to the wire and invokes the callback once the response was obtained or with an * error (socket error or OperationTimedOutError or serialization-related error). * @param {Request} request * @param {ExecutionOptions|null} execOptions * @param {function}
(request, execOptions, callback)
| 522 | * @return {OperationState} |
| 523 | */ |
| 524 | sendStream(request, execOptions, callback) { |
| 525 | execOptions = execOptions || ExecutionOptions.empty(); |
| 526 | |
| 527 | // Create a new operation that will contain the request, callback and timeouts |
| 528 | const operation = new OperationState(request, execOptions.getRowCallback(), (err, response, length) => { |
| 529 | if (!err || !err.isSocketError) { |
| 530 | // Emit that a response was obtained when there is a valid response |
| 531 | // or when the error is not a socket error |
| 532 | this.emit('responseDequeued'); |
| 533 | } |
| 534 | callback(err, response, length); |
| 535 | }); |
| 536 | |
| 537 | const streamId = this._getStreamId(); |
| 538 | |
| 539 | // Start the request timeout without waiting for the request to be written |
| 540 | operation.setRequestTimeout(execOptions, this.options.socketOptions.readTimeout, this.endpoint, |
| 541 | () => this.timedOutOperations++, |
| 542 | () => this.timedOutOperations--); |
| 543 | |
| 544 | if (streamId === null) { |
| 545 | this.log('info', |
| 546 | 'Enqueuing ' + |
| 547 | this._pendingWrites.length + |
| 548 | ', if this message is recurrent consider configuring more connections per host or lowering the pressure'); |
| 549 | this._pendingWrites.push(operation); |
| 550 | return operation; |
| 551 | } |
| 552 | this._write(operation, streamId); |
| 553 | return operation; |
| 554 | } |
| 555 | |
| 556 | /** |
| 557 | * Pushes the item into the queue. |
no test coverage detected