@google-cloud/pubsub
Advanced tools
Comparing version 1.7.2 to 1.7.3
@@ -63,3 +63,5 @@ /*! | ||
numPendingRequests: number; | ||
numInFlightRequests: number; | ||
protected _onFlush?: defer.DeferredPromise<void>; | ||
protected _onDrain?: defer.DeferredPromise<void>; | ||
protected _options: BatchOptions; | ||
@@ -99,2 +101,6 @@ protected _requests: QueuedMessages; | ||
/** | ||
* Returns a promise that resolves when all in-flight messages have settled. | ||
*/ | ||
onDrain(): Promise<void>; | ||
/** | ||
* Set the batching options. | ||
@@ -101,0 +107,0 @@ * |
@@ -59,2 +59,3 @@ "use strict"; | ||
this.numPendingRequests = 0; | ||
this.numInFlightRequests = 0; | ||
this._requests = []; | ||
@@ -84,2 +85,3 @@ this._subscriber = sub; | ||
this.numPendingRequests += 1; | ||
this.numInFlightRequests += 1; | ||
if (this._requests.length >= maxMessages) { | ||
@@ -113,5 +115,10 @@ this.flush(); | ||
} | ||
this.numInFlightRequests -= batchSize; | ||
if (deferred) { | ||
deferred.resolve(); | ||
} | ||
if (this.numInFlightRequests <= 0 && this._onDrain) { | ||
this._onDrain.resolve(); | ||
delete this._onDrain; | ||
} | ||
} | ||
@@ -131,2 +138,11 @@ /** | ||
/** | ||
* Returns a promise that resolves when all in-flight messages have settled. | ||
*/ | ||
onDrain() { | ||
if (!this._onDrain) { | ||
this._onDrain = defer(); | ||
} | ||
return this._onDrain.promise; | ||
} | ||
/** | ||
* Set the batching options. | ||
@@ -133,0 +149,0 @@ * |
@@ -399,2 +399,8 @@ "use strict"; | ||
} | ||
if (this._acks.numInFlightRequests) { | ||
promises.push(this._acks.onDrain()); | ||
} | ||
if (this._modAcks.numInFlightRequests) { | ||
promises.push(this._modAcks.onDrain()); | ||
} | ||
await Promise.all(promises); | ||
@@ -401,0 +407,0 @@ } |
@@ -7,2 +7,9 @@ # Changelog | ||
### [1.7.3](https://www.github.com/googleapis/nodejs-pubsub/compare/v1.7.2...v1.7.3) (2020-05-01) | ||
### Bug Fixes | ||
* **close:** ensure in-flight messages are drained ([#952](https://www.github.com/googleapis/nodejs-pubsub/issues/952)) ([#980](https://www.github.com/googleapis/nodejs-pubsub/issues/980)) ([4731535](https://www.github.com/googleapis/nodejs-pubsub/commit/473153587024bebfad43e8a5df8dcbd13d120402)) | ||
### [1.7.2](https://www.github.com/googleapis/nodejs-pubsub/compare/v1.7.1...v1.7.2) (2020-04-08) | ||
@@ -9,0 +16,0 @@ |
{ | ||
"name": "@google-cloud/pubsub", | ||
"description": "Cloud Pub/Sub Client Library for Node.js", | ||
"version": "1.7.2", | ||
"version": "1.7.3", | ||
"license": "Apache-2.0", | ||
@@ -6,0 +6,0 @@ "author": "Google Inc.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
3498189
57061