Skip to content

Commit 7b5d08c

Browse files
author
Dimitri Nikitopoulos
committed
fix: proper coding styl
1 parent f4073bc commit 7b5d08c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/lib/RosNode.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,10 @@ class RosNode extends EventEmitter {
122122
if (callback && typeof callback === 'function') {
123123
sub.on('message', callback);
124124
}
125-
if (!firstSubscriber && subImpl._latching && subImpl._lastMessage){
126-
sub.emit('message', subImpl._lastMessage)
125+
// Duplicate subscribers wont get a latched 'message' emit from the existing subscriber impl.
126+
// This will forcibly send an emit if the topic is latched and has already seen an incoming message
127+
if (!firstSubscriber && subImpl.getLatching() && subImpl.getLastMessage()) {
128+
sub.emit('message', subImpl.getLastMessage())
127129
}
128130

129131
return sub;

src/lib/impl/SubscriberImpl.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,23 @@ class SubscriberImpl extends EventEmitter {
134134
return this._nodeHandle;
135135
}
136136

137+
/**
138+
* Check if this subscriber is connected to a latched topic
139+
* @returns {boolean}
140+
*/
141+
getLatching() {
142+
return this._latching;
143+
}
144+
145+
/**
146+
* Return the last message received
147+
* @returns {any}
148+
*/
149+
getLastMessage() {
150+
return this._lastMessage;
151+
}
152+
153+
137154
/**
138155
* Clears and closes all client connections for this subscriber.
139156
*/
@@ -425,7 +442,7 @@ class SubscriberImpl extends EventEmitter {
425442
_handleMsgQueue(msgQueue) {
426443
try {
427444
msgQueue.forEach((msg) => {
428-
if(this._latching){
445+
if (this.getLatching()) {
429446
this._lastMessage = this._messageHandler.deserialize(msg);
430447
}
431448
this.emit('message', this._messageHandler.deserialize(msg));

0 commit comments

Comments
 (0)