mgbam commited on
Commit
e5df665
·
verified ·
1 Parent(s): 9fe665b

Create app/broker.py

Browse files
Files changed (1) hide show
  1. app/broker.py +16 -0
app/broker.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ A singleton message broker for the application.
3
+
4
+ This ensures that the same asyncio.Queue instance is shared across all parts
5
+ of the application, including background tasks and API request handlers,
6
+ solving state-sharing issues in ASGI lifecycles.
7
+ """
8
+ import asyncio
9
+
10
+ class SignalBroker:
11
+ def __init__(self):
12
+ self.queue = asyncio.Queue()
13
+
14
+ # Create a single, global instance of the broker.
15
+ # When any file imports 'signal_broker', they will get this exact same object.
16
+ signal_broker = SignalBroker()