feat(mma): Implement AsyncEventQueue in events.py

This commit is contained in:
2026-02-26 20:33:51 -05:00
parent 47d750ea9d
commit 695cb4a82e
3 changed files with 78 additions and 2 deletions

View File

@@ -1,7 +1,8 @@
"""
Decoupled event emission system for cross-module communication.
"""
from typing import Callable, Any, Dict, List
import asyncio
from typing import Callable, Any, Dict, List, Tuple
class EventEmitter:
"""
@@ -35,3 +36,30 @@ class EventEmitter:
if event_name in self._listeners:
for callback in self._listeners[event_name]:
callback(*args, **kwargs)
class AsyncEventQueue:
"""
Asynchronous event queue for decoupled communication using asyncio.Queue.
"""
def __init__(self):
"""Initializes the AsyncEventQueue with an internal asyncio.Queue."""
self._queue: asyncio.Queue = asyncio.Queue()
async def put(self, event_name: str, payload: Any = None):
"""
Puts an event into the queue.
Args:
event_name: The name of the event.
payload: Optional data associated with the event.
"""
await self._queue.put((event_name, payload))
async def get(self) -> Tuple[str, Any]:
"""
Gets an event from the queue.
Returns:
A tuple containing (event_name, payload).
"""
return await self._queue.get()