Give the function parameters slightly more useful names
Evan Huus
9 years ago
45 | 45 | // Run will either return ErrBreakerOpen immediately if the circuit-breaker is |
46 | 46 | // already open, or it will run the given function and pass along its return |
47 | 47 | // value. It is safe to call Run concurrently on the same Breaker. |
48 | func (b *Breaker) Run(x func() error) error { | |
48 | func (b *Breaker) Run(work func() error) error { | |
49 | 49 | b.lock.RLock() |
50 | 50 | state := b.state |
51 | 51 | b.lock.RUnlock() |
60 | 60 | defer func() { |
61 | 61 | panicValue = recover() |
62 | 62 | }() |
63 | return x() | |
63 | return work() | |
64 | 64 | }() |
65 | 65 | |
66 | 66 | if result == nil && panicValue == nil && state == closed { |
85 | 85 | // If the function is run, Go will return nil immediately, and will *not* return |
86 | 86 | // the return value of the function. It is safe to call Go concurrently on the |
87 | 87 | // same Breaker. |
88 | func (b *Breaker) Go(x func() error) error { | |
88 | func (b *Breaker) Go(work func() error) error { | |
89 | 89 | b.lock.RLock() |
90 | 90 | state := b.state |
91 | 91 | b.lock.RUnlock() |
101 | 101 | defer func() { |
102 | 102 | panicValue = recover() |
103 | 103 | }() |
104 | return x() | |
104 | return work() | |
105 | 105 | }() |
106 | 106 | |
107 | 107 | if result == nil && panicValue == nil && state == closed { |