Browse Source

Short-circuit the fast path without locking

Evan Huus 11 năm trước cách đây
mục cha
commit
c7ef7e79cd
1 tập tin đã thay đổi với 6 bổ sung0 xóa
  1. 6 0
      breaker/breaker.go

+ 6 - 0
breaker/breaker.go

@@ -64,6 +64,12 @@ func (b *Breaker) Run(x func() error) error {
 		return x()
 	}()
 
+	if result == nil && panicValue == nil && state == closed {
+		// short-circuit the normal, success path without contending
+		// on the lock
+		return nil
+	}
+
 	b.processResult(result, panicValue)
 
 	if panicValue != nil {