Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

What exactly does the spin function do ? I thought it is used for callbacks.

It does call callbacks.

At this point it seems that the auto node = std::make_shared<ClassName>(topic); has completely been executed as i goes again to the main (why?)

If I understand correctly the question is why the lambda auto_publish was not executed in the constructor? It's because it was never called in the constructor. It was defined, but not called.

Does that mean that the auto_publish function in the constructor is called by spin?

Yes. This line in the constructor created a timer: timer_ = this->create_wall_timer(2s, publish_message);. It calls the callback publish_message (a lambda) every 2 seconds.

More info about lambdas here http://en.cppreference.com/w/cpp/language/lambda