Skip to content

Commit

Permalink
perf: avoid heap allocations in the LazyDo
Browse files Browse the repository at this point in the history
Signed-off-by: Rueian <[email protected]>
  • Loading branch information
rueian committed Nov 8, 2024
1 parent 02be79e commit 38c86fe
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions singleflight.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ func (c *call) LazyDo(threshold time.Duration, fn func() error) {
c.cn++
ts := c.ts
c.mu.Unlock()
go func(threshold time.Duration, ch chan struct{}, fn func() error) {
time.Sleep(time.Until(ts.Add(threshold)))
go func(ts time.Time, ch chan struct{}, fn func() error) {
time.Sleep(time.Until(ts))
c.do(ch, fn)
}(threshold, ch, fn)
}(ts.Add(threshold), ch, fn)
}

func (c *call) do(ch chan struct{}, fn func() error) (err error) {
Expand Down

0 comments on commit 38c86fe

Please sign in to comment.