Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate subscribe messages! #343

Open
fabioaraujopt opened this issue Sep 23, 2019 · 7 comments
Open

Duplicate subscribe messages! #343

fabioaraujopt opened this issue Sep 23, 2019 · 7 comments

Comments

@fabioaraujopt
Copy link

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

@Rayman
Copy link
Contributor

Rayman commented Sep 23, 2019

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

@fabioaraujopt
Copy link
Author

Can you show me example? Didn't understand

@Rayman
Copy link
Contributor

Rayman commented Sep 24, 2019

Something like this (not tested)

function handler(message) {
	console.log(message);
	listener.unsubscribe(handler);
}

listener.subscribe(handler);

@asvinp
Copy link

asvinp commented May 18, 2020

Can you show me example? Didn't understand

Hey, did you figure out the solution for this?

@ManuelZ
Copy link

ManuelZ commented Feb 18, 2021

@asvinp @fabioaraujopt Any solution?

I'm unsuscribing by providing the callback to the unsubscribe function but I'm ending up with an error.

@ManuelZ
Copy link

ManuelZ commented Feb 18, 2021

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()

@asvinp
Copy link

asvinp commented Apr 15, 2021

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?

k-aguete pushed a commit to k-aguete/roslibjs that referenced this issue Oct 21, 2022
* Refactor OccupancyGrid to add two methods. These methods can be overwritten by subclasses to
extend the OccupancyGrid's rendering behavior (for example adding a colormapping feature).

* getColor() - determine the color for a data cell
* getValue() - determine the value for a data cell

* Change method documentation to mention rgba support

* Track resources and add dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants