How composed EventSources process events
masterWhen building a complex EventSource that is composed of multiple sub-sources (e.g., a channel, a ping source, and a socket), the process_events implementation should recursively call the process_events method of each sub-source.
The Role of the Token
The token passed into the top-level process_events is the mechanism used to determine which sub-source is responsible for the current wakeup. Each sub-source compares the provided token against its own registered token. If they match, the sub-source executes its logic and calls the provided callback.
Workflow
- The loop wakes up and calls
process_eventson the composed source. - The composed source calls
sub_source.process_events(readiness, token, callback)for each component. - If
token == sub_source.token, the sub-source processes its internal events. - The composed source then returns a
PostAction(usuallyPostAction::Continue) to the loop.