Duplicate subscribe messages!
I'm using the following configuration:
`var ros = new ROSLIB.Ros({ url : 'ws://x.x.x.x:9090' });
listener=new ROSLIB.Topic({ ros : ros, name : '/vigil/sensor/gps/navsatfix', messageType : 'sensor_msgs/NavSatFix' });
listener.subscribe(function(message){ listener.unsubscribe(); console.log(message); }); ` I placed the subscribe function inside a javascript setInterval, in order to call it everytime i need data, instead of being always listening to broadcast. However every time a new subscribe is done. The number of response doubles. (I think it receives all messages from begin).
first_call -> 1 log first_call -> 3 logs first_call -> 4 logs first_call -> 5 logs first_call -> 6 logs
Quote from the documentation
unsubscribe(callback)
Unregisters as a subscriber for the topic. Unsubscribing stop remove all subscribe callbacks. To remove a call back, you must explicitly pass the callback function in.
callback: the optional callback to unregister, if * provided and other listeners are registered the topic won't * unsubscribe, just stop emitting to the passed listener
Can you show me example? Didn't understand
Something like this (not tested)
function handler(message) {
console.log(message);
listener.unsubscribe(handler);
}
listener.subscribe(handler);
Can you show me example? Didn't understand
Hey, did you figure out the solution for this?
@asvinp @fabioaraujopt Any solution?
I'm unsuscribing by providing the callback to the unsubscribe function but I'm ending up with an error.
I had this issue when using React Hooks.
I was clicking a button to get subscribed and then again the same button to get unsubscribed from a topic.
- I had my topics declarations inside my component... solution, to move them out.
- I needed to memoize the function that I was using to switch the subscription on/off and as well memoize the function callback passed to topic.unsubscribe()
I had this issue when using React Hooks.
I was clicking a button to get subscribed and then again the same button to get unsubscribed from a topic.
- I had my topics declarations inside my component... solution, to move them out.
- I needed to memoize the function that I was using to switch the subscription on/off and as well memoize the function callback passed to topic.unsubscribe()
@ManuelZ If possible could you show an example?