代码提交
This commit is contained in:
1 parent
d93cc62806
commit
ddf83f7728
25 files changed
+4086
-424
No files matched your search
@@ -251,34 +251,30 @@ class ConversationEventHub:
|
||||
return seen_gen
|
||||
return state.generation
|
||||
|
||||
def shutdown(self) -> None:
|
||||
"""Signal all subscribers to stop (server shutdown).
|
||||
async def aclose(self) -> None:
|
||||
"""Async shutdown that immediately wakes all subscribers.
|
||||
|
||||
Wakes every waiter; their ``wait_for_change`` returns ``True`` but
|
||||
the caller's outer loop checks ``hub.is_closed`` and exits.
|
||||
Acquires each Condition lock, bumps generation, and calls
|
||||
``notify_all()`` so every waiter returns within milliseconds —
|
||||
not after the next heartbeat timeout.
|
||||
"""
|
||||
self._closed = True
|
||||
for state in list(self._convs.values()):
|
||||
async with state.condition:
|
||||
state.generation += 1
|
||||
state.condition.notify_all()
|
||||
|
||||
def shutdown(self) -> None:
|
||||
"""Deprecated sync stub — bumps generation but cannot wake waiters
|
||||
immediately. Callers should use ``await hub.aclose()`` instead."""
|
||||
self._closed = True
|
||||
for state in self._convs.values():
|
||||
state.generation += 1
|
||||
# Wake all waiters — we can't use the condition here because
|
||||
# shutdown is sync. The next wait_for_change call will see
|
||||
# the incremented generation and return immediately.
|
||||
# For a truly sync wake we'd need to schedule the notify;
|
||||
# but since shutdown is called from the lifespan teardown
|
||||
# (async context), callers should use:
|
||||
# async with state.condition: state.condition.notify_all()
|
||||
# Instead we just bump the generation; waiters time out on the
|
||||
# next heartbeat cycle at worst (15s). For immediate wake,
|
||||
# use `await hub.aclose()` below.
|
||||
|
||||
|
||||
async def hub_aclose(hub: ConversationEventHub) -> None:
|
||||
"""Async shutdown that immediately wakes all subscribers."""
|
||||
hub._closed = True
|
||||
for state in list(hub._convs.values()):
|
||||
async with state.condition:
|
||||
state.generation += 1
|
||||
state.condition.notify_all()
|
||||
await hub.aclose()
|
||||
|
||||
|
||||
__all__ = ["ConversationEventHub", "Subscription", "hub_aclose"]
|
||||
Reference in new issue
Block a user