event: use defer

This commit is contained in:
Felix Lange 2020-04-16 16:01:40 +02:00 committed by GitHub
parent 255e927d0b
commit 9a1a27ab7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -104,6 +104,7 @@ func (mux *TypeMux) Post(ev interface{}) error {
// Stop blocks until all current deliveries have finished.
func (mux *TypeMux) Stop() {
mux.mutex.Lock()
defer mux.mutex.Unlock()
for _, subs := range mux.subm {
for _, sub := range subs {
sub.closewait()
@ -111,11 +112,11 @@ func (mux *TypeMux) Stop() {
}
mux.subm = nil
mux.stopped = true
mux.mutex.Unlock()
}
func (mux *TypeMux) del(s *TypeMuxSubscription) {
mux.mutex.Lock()
defer mux.mutex.Unlock()
for typ, subs := range mux.subm {
if pos := find(subs, s); pos >= 0 {
if len(subs) == 1 {
@ -125,7 +126,6 @@ func (mux *TypeMux) del(s *TypeMuxSubscription) {
}
}
}
mux.mutex.Unlock()
}
func find(slice []*TypeMuxSubscription, item *TypeMuxSubscription) int {