Merge pull request '[agent/codex:gpt-5.4-mini] Read ~/spec/code/core/go/store/RFC.md fully. Find features d...' (#77) from agent/read---spec-code-core-go-store-rfc-md-fu into dev
This commit is contained in:
commit
7141ff69ed
1 changed files with 21 additions and 2 deletions
23
events.go
23
events.go
|
|
@ -82,11 +82,17 @@ func (storeInstance *Store) Watch(group string) <-chan Event {
|
|||
eventChannel := make(chan Event, watcherEventBufferCapacity)
|
||||
|
||||
storeInstance.watchersLock.Lock()
|
||||
defer storeInstance.watchersLock.Unlock()
|
||||
storeInstance.closeLock.Lock()
|
||||
closed = storeInstance.closed
|
||||
storeInstance.closeLock.Unlock()
|
||||
if closed {
|
||||
return closedEventChannel()
|
||||
}
|
||||
if storeInstance.watchers == nil {
|
||||
storeInstance.watchers = make(map[string][]chan Event)
|
||||
}
|
||||
storeInstance.watchers[group] = append(storeInstance.watchers[group], eventChannel)
|
||||
storeInstance.watchersLock.Unlock()
|
||||
|
||||
return eventChannel
|
||||
}
|
||||
|
|
@ -156,8 +162,14 @@ func (storeInstance *Store) OnChange(callback func(Event)) func() {
|
|||
callbackRegistration := changeCallbackRegistration{registrationID: registrationID, callback: callback}
|
||||
|
||||
storeInstance.callbacksLock.Lock()
|
||||
defer storeInstance.callbacksLock.Unlock()
|
||||
storeInstance.closeLock.Lock()
|
||||
closed = storeInstance.closed
|
||||
storeInstance.closeLock.Unlock()
|
||||
if closed {
|
||||
return func() {}
|
||||
}
|
||||
storeInstance.callbacks = append(storeInstance.callbacks, callbackRegistration)
|
||||
storeInstance.callbacksLock.Unlock()
|
||||
|
||||
// Return an idempotent unregister function.
|
||||
var once sync.Once
|
||||
|
|
@ -194,6 +206,13 @@ func (storeInstance *Store) notify(event Event) {
|
|||
}
|
||||
|
||||
storeInstance.watchersLock.RLock()
|
||||
storeInstance.closeLock.Lock()
|
||||
closed = storeInstance.closed
|
||||
storeInstance.closeLock.Unlock()
|
||||
if closed {
|
||||
storeInstance.watchersLock.RUnlock()
|
||||
return
|
||||
}
|
||||
for _, registeredChannel := range storeInstance.watchers["*"] {
|
||||
select {
|
||||
case registeredChannel <- event:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue