ExecuteQueryStateMachine

ExecuteQueryStateMachine

This object handles creating and piping the streams which are used to process the responses from the server. It's main purpose is to make sure that the callerStream, which the user gets as a result of Instance.executeQuery, behaves properly:

  • closes in case of a failure
  • doesn't close in case of a retryable error.

We create the following streams: responseStream -> byteBuffer -> readerStream -> resultStream

The last two (readerStream and resultStream) are connected and returned to the caller - hence called the callerStream.

When a request is made responseStream and byteBuffer are created, connected and piped to the readerStream.

On retry, the old responseStream-byteBuffer pair is discarded and a new pair is crated.

For more info please refer to the State type

Constructor

new ExecuteQueryStateMachine()

Members

handleCallersEnd

The caller should be able to call callerStream.end() to stop receiving more rows and cancel the stream prematurely. However this has a side effect the 'end' event will be emitted. We don't want that, because it also gets emitted if the stream ended normally. To tell these two situations apart, we'll overwrite the end function, but save the "original" end() function which will be called on valuesStream.on('end').

handleStreamData

This method is called when the valuesStream emits data. The valuesStream yelds data only after the resume token is recieved, hence the state change.