Improve: fix go test race detect

This commit is contained in:
Dreamacro
2020-07-18 20:56:13 +08:00
parent 6c7a8fffe0
commit cf9e1545a4
3 changed files with 19 additions and 12 deletions

View File

@ -44,9 +44,12 @@ func (s *Single) Do(fn func() (interface{}, error)) (v interface{}, err error, s
s.mux.Unlock()
call.val, call.err = fn()
call.wg.Done()
s.mux.Lock()
s.call = nil
s.result = &Result{call.val, call.err}
s.last = now
s.mux.Unlock()
return call.val, call.err, false
}