Skip to main content
find(...) is the unified lookup API: search history, wait for future events, or combine both.

Interface

await bus.find(
    event_type,                            # Event class, event type string, or '*'
    where: Callable[[BaseEvent], bool] | None = None,
    child_of: BaseEvent | None = None,
    past: bool | float | timedelta = True,
    future: bool | float = False,
    **event_fields,                        # equality filters (event_status='completed', request_id='abc', ...)
)

Option semantics

  • past
    • true: search all history (default)
    • false: skip history
    • number (or timedelta in Python): search recent history window
  • future
    • false: do not wait (default)
    • true: wait indefinitely
    • number: wait up to N seconds
  • where: predicate filter
  • child_of: match only descendants of the given parent event
  • event_fields: strict equality filters on event fields/metadata
Default behavior when omitted is history-only lookup (past=True, future=False).

Common use cases

1) History lookup only (non-blocking)

existing = await bus.find(ResponseEvent)

2) Wait only for future events

future = await bus.find(ResponseEvent, past=False, future=5)

3) Check recent history, then keep waiting briefly

match = await bus.find(ResponseEvent, past=5, future=5)

4) Filter by fields + predicate

match = await bus.find(
    ResponseEvent,
    where=lambda e: e.request_id == my_id,
    event_status='completed',
    future=5,
)

5) Wildcard lookup across all event types

any_completed = await bus.find(
    '*',
    where=lambda e: e.event_type.endswith('ResultEvent'),
    event_status='completed',
    future=5,
)

6) Find descendants of a specific parent event

parent_event = await bus.emit(NavigateToUrlEvent(url='https://example.com'))
child = await bus.find(TabCreatedEvent, child_of=parent_event, past=5)

7) Debounce expensive work

event = (
    await bus.find(ScreenshotEvent, past=10, future=False)
    or await bus.find(ScreenshotEvent, past=False, future=5)
    or bus.emit(ScreenshotEvent())
)
await event

Important behavior

  • find() resolves when an event is emitted, not when handlers finish.
  • To wait for handler completion, await the returned event (await event in Python, await event.done() in TypeScript).
  • If no match is found (or future times out), find() returns None / null.
  • If both past and future are false, it returns immediately with no match.