MCPcopy Create free account
hub / github.com/astercloud/aster / Close

Method Close

pkg/events/bus.go:156–185  ·  view source on GitHub ↗

Close 关闭事件总线,释放资源

()

Source from the content-addressed store, hash-verified

154
155// Close 关闭事件总线,释放资源
156func (eb *EventBus) Close() {
157 // 先停止清理 worker(不持锁,避免死锁)
158 if eb.cleanupDone != nil {
159 close(eb.cleanupDone)
160 eb.cleanupWg.Wait() // 等待清理 goroutine 完全退出
161 eb.cleanupDone = nil
162 }
163
164 // 然后清理所有资源(持锁)
165 eb.mu.Lock()
166 defer eb.mu.Unlock()
167
168 // 关闭所有订阅 channel
169 for id, ch := range eb.progressSubs {
170 close(ch)
171 delete(eb.progressSubs, id)
172 }
173 for id, ch := range eb.controlSubs {
174 close(ch)
175 delete(eb.controlSubs, id)
176 }
177 for id, ch := range eb.monitorSubs {
178 close(ch)
179 delete(eb.monitorSubs, id)
180 }
181
182 // 清空数据
183 eb.timeline = nil
184 eb.bookmarks = nil
185}
186
187// emit 发送事件到总线(内部方法)
188func (eb *EventBus) emit(channel types.AgentChannel, event any) types.AgentEventEnvelope {

Callers 9

TestNewEventBusFunction · 0.95
TestEmitAndSubscribeFunction · 0.95
TestUnsubscribeFunction · 0.95
TestCloseFunction · 0.95
TestGetTimelineRangeFunction · 0.95
TestGetTimelineSinceFunction · 0.95
TestGetTimelineFilteredFunction · 0.95
TestGetTimelineCountFunction · 0.95

Calls 2

deleteFunction · 0.85
WaitMethod · 0.80

Tested by 9

TestNewEventBusFunction · 0.76
TestEmitAndSubscribeFunction · 0.76
TestUnsubscribeFunction · 0.76
TestCloseFunction · 0.76
TestGetTimelineRangeFunction · 0.76
TestGetTimelineSinceFunction · 0.76
TestGetTimelineFilteredFunction · 0.76
TestGetTimelineCountFunction · 0.76