NewEventBusWithConfig 创建带配置的事件总线
(config *EventBusConfig)
| 64 | |
| 65 | // NewEventBusWithConfig 创建带配置的事件总线 |
| 66 | func NewEventBusWithConfig(config *EventBusConfig) *EventBus { |
| 67 | if config == nil { |
| 68 | config = DefaultEventBusConfig() |
| 69 | } |
| 70 | |
| 71 | eb := &EventBus{ |
| 72 | config: config, |
| 73 | timeline: make([]types.AgentEventEnvelope, 0, 1000), |
| 74 | bookmarks: make(map[int64]types.Bookmark), |
| 75 | progressSubs: make(map[string]chan types.AgentEventEnvelope), |
| 76 | controlSubs: make(map[string]chan types.AgentEventEnvelope), |
| 77 | monitorSubs: make(map[string]chan types.AgentEventEnvelope), |
| 78 | controlHandlers: make(map[string][]EventHandler), |
| 79 | monitorHandlers: make(map[string][]EventHandler), |
| 80 | cleanupDone: make(chan struct{}), |
| 81 | } |
| 82 | |
| 83 | // 启动清理 worker |
| 84 | eb.startCleanupWorker() |
| 85 | |
| 86 | return eb |
| 87 | } |
| 88 | |
| 89 | // startCleanupWorker 启动后台清理协程 |
| 90 | func (eb *EventBus) startCleanupWorker() { |