The other answer is correct, but I would like to post a more complete global overview of what the executor is doing in the background. I feel like this is a big mystery to a lot of people working with ROS2.
For clarification I'm talking about the SingleThreadedExecutor that was in ROS2 before the Foxy release. The static executor released in Foxy works slightly differently.
How the executor works:
During Node initialization handles to nodes, callbackgroups, timers, subscriptions etc. are created in RCL and RMW. The information contained in a Node is added to the executor using a weak pointer.
start of a spin()
- The executor finds nothing to execute
- The executor performs collect_entities (gets handles from RCL)
- The executor creates a wait_set using these handles
- The executor communicates with RMW (DDS layer) to see what callbacks are ready to execute. If something is not ready to execute replace the handle in the wait-set with NULL
- The NULL handles are removed from the wait_set. Meaning you are now left with a wait-set containing only things that need to be executed (during this spin) instead of all things that exist.
- The executor looks for the next thing to execute in the following order: timers, subscriptions, services, clients, waitables. So if a ready timer exists it will search for the corresponding timer-callback. If there are no timers it will execute the first subscription-callback it can find etc. To find a corresponding callback, the executor searches a tree of weak-ptrs to the nodes that are part of the executor.
- Once it finds the correct callback in the correct callbackgroup in the correct node it will execute it and remove the handle from the wait-set.
- As long as there are still things to execute, meaning the wait-set is not empty yet, repeat 6 till 7, if nothing is left to execute go to 1 (next spin cycle).
At the start of the next spin cycle, the wait-set is completely filled again, all elements are checked to see if they are ready and they are all executed in order again.
So like the other answer states. Yes, both callbacks will be executed. Do keep in mind that the RMW calls are only made at the start of a spin(). So any messages coming in while the executor is finishing spin1 (processing all the ready callbacks) will not be seen until spin2.