Ask Your Question

int callback

asked 2012-07-26 07:07:57 -0500

Rydel gravatar image

Is it possible to have a callback function other than type void? If yes, how would you handle a situation where you call ros::spinOnce() and say you are subscribing to two different topics each with their own callback function... how would you store the variable that one of the callback functions returned?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2012-07-26 07:10:21 -0500

dornhege gravatar image

updated 2012-07-27 02:10:39 -0500

I would say: No.

For the reason that you basically explained yourself: What would one do with the return value?, What is the meaning of that?

PS: Maybe, your intended usage of ros::spinOnce is based on a misconception. ros::spinOnce will not call one callback, but all available callbacks at the time. For more information, see:

edit flag offensive delete link more


Possibly a boolean return? That could be useful in some scenario.

allenh1 gravatar image allenh1  ( 2012-07-26 09:55:04 -0500 )edit

But who would use that? Callbacks come from spin, so what should happen in spin if a callback returns false? Things like error handling in client code should not go through spin, but be handled directly by the callback (IMO). Figuring out what callback caused a false return would also be messy.

dornhege gravatar image dornhege  ( 2012-07-27 02:02:23 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2012-07-26 07:07:57 -0500

Seen: 589 times

Last updated: Jul 27 '12