Skip to content

Commit 0805051

Browse files
fgiorgettikornys
authored andcommitted
Fixed validation of sent messages count (#26)
1 parent 45031b9 commit 0805051

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/senderClient.js

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,21 @@ class Sender extends CoreClient {
102102
}
103103
}
104104

105+
/**
106+
* @method _getTotalSent
107+
* @private
108+
* @description total messages sent excluding released ones (when not using best effort)
109+
* @memberof Sender
110+
*/
111+
_getTotalSent() {
112+
let totalSent = this.sent;
113+
// If using best-effort, then simply ignore released messages
114+
if (!this.options.linkAtMostOnce) {
115+
totalSent -= this.released;
116+
}
117+
return totalSent;
118+
}
119+
105120
/**
106121
* @method _sendMessage
107122
* @private
@@ -114,12 +129,7 @@ class Sender extends CoreClient {
114129
this._nextRequest(context, this);
115130
} else {
116131
let message = undefined;
117-
let totalSent = this.sent;
118-
// If using best-effort, then simply ignore released messages
119-
if (!this.options.linkAtMostOnce) {
120-
totalSent -= this.released;
121-
}
122-
while ((this.options.anonymous || (context.sender && context.sender.sendable())) && totalSent < this.options.count) {
132+
while ((this.options.anonymous || (context.sender && context.sender.sendable())) && this._getTotalSent() < this.options.count) {
123133
this.sent++;
124134
message = this._createMessage(this.sent - 1);
125135

0 commit comments

Comments
 (0)