Pyeventbus异步事件处理框架

联合创作 · 2023-09-28 17:11

Pyeventbus是个十分轻巧的异步事件处理框架。

特性:

  1. Pyeventbus 会检查你的事件消息类型和侦听器的类型的合法性,侦听器和消息需要被正确的创建

  2. 允许一个事件消息有多个对应的处理方法,事件处理的时间复杂度是O(k)的,取决于你的侦听处理函数有多少个

  3. 支持同步和异步事件处理,可自定义异步事件处理线程池大小

示例代码:

from eventbus.eventbus import EventBus
#now create a eventbus,the default pool size is 4 and isdaemon is true
eventbus=EventBus()

#add the listener to eventbus so it will use the right handler to process the event
eventbus.register(Listener())

#now the event message were sent,eventbus will process
#this is for the async post
eventbus.async_post(GreetEvent())

#this is for the sync post
eventbus.post(GreetEvent())

#remove the listener
eventbus.unregister(Listener())

#destroy the eventbus
eventbus.destroy()
浏览 7
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报