(params)
| 203 | } |
| 204 | |
| 205 | _executeOne(params) { |
| 206 | if (!Array.isArray(params)) { |
| 207 | return this._setReadEnded(new TypeError('Stream should be in objectMode and should emit Array instances')); |
| 208 | } |
| 209 | |
| 210 | if (this._readEnded) { |
| 211 | // Read ended abruptly because of incorrect format or error event being emitted. |
| 212 | // We shouldn't consider additional items. |
| 213 | return; |
| 214 | } |
| 215 | |
| 216 | const index = this._index++; |
| 217 | this._inFlight++; |
| 218 | |
| 219 | this._client.execute(this._query, params, this._queryOptions) |
| 220 | .then(rs => { |
| 221 | this._result.setResultItem(index, rs); |
| 222 | this._inFlight--; |
| 223 | }) |
| 224 | .catch(err => { |
| 225 | this._inFlight--; |
| 226 | this._setError(index, err); |
| 227 | }) |
| 228 | .then(() => { |
| 229 | if (this._stream.isPaused()) { |
| 230 | this._stream.resume(); |
| 231 | } |
| 232 | |
| 233 | if (this._readEnded && this._inFlight === 0) { |
| 234 | // When read ended and there are no more in-flight requests |
| 235 | // We yield the result to the user. |
| 236 | // It could have ended prematurely when there is a read error |
| 237 | // or there was an execution error and raiseOnFirstError is true |
| 238 | // In that case, calling the resolve callback has no effect |
| 239 | this._resolveCallback(this._result); |
| 240 | } |
| 241 | }); |
| 242 | |
| 243 | if (this._inFlight >= this._concurrencyLevel) { |
| 244 | this._stream.pause(); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * Marks the stream read process as ended. |
no test coverage detected