Currently .expect(...) is only for awaiting future events to be dispatched, but often you want to expect an event that might already have been dispatched. e.g.
def on_SwitchTabEvent(self, event: SwitchTabEvent):
...
if no_tabs_open:
nav_event = await self.event_bus.dispatch(NavigateToUrlEvent(url='about:blank', new_tab=True))
# this event ^ synchronously creates the new tab, so by time we get to the next line below
# TabCreatedEvent has already been dispatched and handled, so this doesn't work currently:
# new_tab = self.event_bus.expect(TabCreatedEvent)
new_tab = await self.event_bus.find_recent(TabCreatedEvent, child_of=nav_event)
We can potentially dedupe/merge this with the needs of EventBus.get_or_dispatch(...):
Might be possible to just make one method for both and control behavior with args.
Currently
.expect(...)is only for awaiting future events to be dispatched, but often you want to expect an event that might already have been dispatched. e.g.We can potentially dedupe/merge this with the needs of
EventBus.get_or_dispatch(...):EventBus.get_or_dispatch(SomeEvent, include=..., exclude=...)#10Might be possible to just make one method for both and control behavior with args.