Spaces:
Sleeping
Sleeping
File size: 513 Bytes
e5df665 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
"""
A singleton message broker for the application.
This ensures that the same asyncio.Queue instance is shared across all parts
of the application, including background tasks and API request handlers,
solving state-sharing issues in ASGI lifecycles.
"""
import asyncio
class SignalBroker:
def __init__(self):
self.queue = asyncio.Queue()
# Create a single, global instance of the broker.
# When any file imports 'signal_broker', they will get this exact same object.
signal_broker = SignalBroker() |