GraiaProject / BroadcastControl

a high performance, highly customizable, elegantly designed event system based on asyncio
32 stars 7 forks source link

因 Depend.target 内创建了嵌套Executor 造成的同一 dispatcher 的方法相对于同个事件被多次执行 #61

Closed RF-Tar-Railt closed 1 year ago

RF-Tar-Railt commented 1 year ago

假设一个listener:

class TestDispatcher:
    async def beforeExecution(...):
        print(1)
@bcc.receiver(Event, dispatchers=[TestDispatcher()], decorators=[Depend(...), Depend(...), Depend(...)])
async def _(...)

当事件传入时,TestDispatcher.beforeExecution 将被执行4次 若有通过 Dispatcher 构建频率控制组件的功能,该特性将造成预期之外的后果

RF-Tar-Railt commented 1 year ago

或许可以设定参数让Executor是否只运行dispatcher.catch?

GreyElaina commented 1 year ago

可以为 Broadcast.executor 添加参数 lifespan: bool = True 以控制 executor 是否触发生命周期回调.