mattermost-community-enterp.../vendor/github.com/redis/rueidis/singleflight.go
Claude ec1f89217a Merge: Complete Mattermost Server with Community Enterprise
Full Mattermost server source with integrated Community Enterprise features.
Includes vendor directory for offline/air-gapped builds.

Structure:
- enterprise-impl/: Enterprise feature implementations
- enterprise-community/: Init files that register implementations
- enterprise/: Bridge imports (community_imports.go)
- vendor/: All dependencies for offline builds

Build (online):
  go build ./cmd/mattermost

Build (offline/air-gapped):
  go build -mod=vendor ./cmd/mattermost

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-17 23:59:07 +09:00

73 lines
1.1 KiB
Go

package rueidis
import (
"context"
"sync"
"time"
)
type call struct {
ts time.Time
ch chan struct{}
cn int
mu sync.Mutex
}
func (c *call) Do(ctx context.Context, fn func() error) error {
c.mu.Lock()
c.cn++
ch := c.ch
if ch != nil {
c.mu.Unlock()
if ctxCh := ctx.Done(); ctxCh != nil {
select {
case <-ch:
case <-ctxCh:
return ctx.Err()
}
} else {
<-ch
}
return nil
}
ch = make(chan struct{})
c.ch = ch
c.mu.Unlock()
return c.do(ch, fn)
}
func (c *call) LazyDo(threshold time.Duration, fn func() error) {
c.mu.Lock()
ch := c.ch
if ch != nil {
c.mu.Unlock()
return
}
ch = make(chan struct{})
c.ch = ch
c.cn++
ts := c.ts
c.mu.Unlock()
go func(ts time.Time, ch chan struct{}, fn func() error) {
time.Sleep(time.Until(ts))
c.do(ch, fn)
}(ts.Add(threshold), ch, fn)
}
func (c *call) do(ch chan struct{}, fn func() error) (err error) {
err = fn()
c.mu.Lock()
c.ch = nil
c.cn = 0
c.ts = time.Now()
c.mu.Unlock()
close(ch)
return
}
func (c *call) suppressing() int {
c.mu.Lock()
defer c.mu.Unlock()
return c.cn
}