Skip to content

Commit ee123ad

Browse files
committed
reducing the execution range of locks to improve concurrency has a significant improvement on the DoChan method
1 parent 913fb63 commit ee123ad

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

singleflight/singleflight.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,11 @@ func (g *Group) doCall(c *call, key string, fn func() (interface{}, error)) {
154154
}
155155

156156
g.mu.Lock()
157-
defer g.mu.Unlock()
158157
c.wg.Done()
159158
if g.m[key] == c {
160159
delete(g.m, key)
161160
}
162-
161+
g.mu.Unlock()
163162
if e, ok := c.err.(*panicError); ok {
164163
// In order to prevent the waiting channels from being blocked forever,
165164
// needs to ensure that this panic cannot be recovered.

0 commit comments

Comments
 (0)