async def initialize_listener(payload: ListenPayload):
    """Initialize a state listener.

    Args:
        payload: a :class:`fiftyone.core.session.events.ListenPayload`

    Returns:
        an :class:`InitializedListener`
    """
    coroutine, is_app, state = await fou.run_sync_task(
        initialize_listener_sync, payload
    )
    if coroutine:
        await coroutine

    request_listeners: t.Set[t.Tuple[str, Listener]] = set()
    for event_name in payload.events:
        listener = Listener(
            queue=asyncio.LifoQueue(maxsize=1000),
            subscription=payload.subscription,
        )
        get_listeners()[event_name].add(listener)
        request_listeners.add((event_name, listener))

    get_requests()[payload.subscription] = request_listeners

    return InitializedListener(is_app, request_listeners, state)
Initialize a state listener.

    Args:
        payload: a :class:`fiftyone.core.session.events.ListenPayload`

    Returns:
        an :class:`InitializedListener`
    
fiftyone/server/events/initialize.py