Skip to content

Commit 670b091

Browse files
committed
Make sure comparison works
1 parent 5e51eeb commit 670b091

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

lib/gateway.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1653,31 +1653,33 @@ class Gateway extends EventEmitter {
16531653
createServerSentEvent (executionUuid, logId, eventName, value, silent = false, greaterThanTimestamp = null) {
16541654
let sseInstance = this._serverSentEvents[executionUuid];
16551655
let timestamp = new Date().toISOString();
1656-
if (greaterThanTimestamp && timestamp < greaterThanTimestamp) {
1657-
timestamp = greaterThanTimestamp;
1656+
// Incremenet this counter so IDs don't overlap
1657+
let i = 0;
1658+
if (greaterThanTimestamp && timestamp <= greaterThanTimestamp) {
1659+
let unixTimestamp = new Date(greaterThanTimestamp).valueOf();
1660+
timestamp = new Date(unixTimestamp + 1).toISOString();
16581661
}
1659-
if (sseInstance) {
1662+
if (silent || sseInstance) {
16601663
let printId = true;
16611664
if (logId === -1) {
16621665
printId = false;
16631666
logId = null;
16641667
}
16651668
if (!logId) {
1666-
let i = 0;
16671669
let lpad = (i, len) => {
16681670
let s = i.toString();
16691671
return '0'.repeat(Math.max(0, len - s.length)) + s;
16701672
};
16711673
let endChar = timestamp[timestamp.length - 1];
16721674
let time = timestamp.slice(0, -1);
16731675
logId = [time, lpad(i++, 6), endChar, '/', executionUuid].join('');
1674-
while (sseInstance.ids[logId]) {
1676+
while (!silent && sseInstance.ids[logId]) {
16751677
logId = [time, lpad(i++, 6), endChar, '/', executionUuid].join('');
16761678
}
16771679
}
1678-
if (!sseInstance.ids[logId]) {
1679-
sseInstance.ids[logId] = true;
1680+
if (silent || !sseInstance.ids[logId]) {
16801681
if (!silent) {
1682+
sseInstance.ids[logId] = true;
16811683
sseInstance.buffer = Buffer.concat([
16821684
sseInstance.buffer,
16831685
Buffer.from([

0 commit comments

Comments
 (0)