Skip to content

New Feature Idea: New params expect(EventType, child_of=parent_event, past=True) to include recent events already completed in last 10 seconds #15

@pirate

Description

@pirate

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions