newtw2
This commit is contained in:
@@ -29,8 +29,11 @@ class AsyncEventBus:
|
||||
tasks.append(asyncio.create_task(callback(**kwargs)))
|
||||
|
||||
if tasks:
|
||||
await asyncio.gather(*tasks, return_exceptions=True)
|
||||
logger.info(f"[EventBus] 事件 {event_type} 已成功广播给 {len(tasks)} 个订阅者")
|
||||
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||
for i, r in enumerate(results):
|
||||
if isinstance(r, Exception):
|
||||
logger.error(f"[EventBus] 事件 {event_type} 订阅者 {i} 异常: {r}")
|
||||
logger.info(f"[EventBus] 事件 {event_type} 已广播给 {len(tasks)} 个订阅者")
|
||||
|
||||
# 全局单例,所有模块共用这一个广播台
|
||||
bus = AsyncEventBus()
|
||||
|
||||
Reference in New Issue
Block a user