MCPcopy
hub / github.com/redis/go-redis / NewFastSemaphore

Function NewFastSemaphore

internal/semaphore.go:30–40  ·  view source on GitHub ↗

NewFastSemaphore creates a new fast semaphore with the given capacity.

(capacity int32)

Source from the content-addressed store, hash-verified

28
29// NewFastSemaphore creates a new fast semaphore with the given capacity.
30func NewFastSemaphore(capacity int32) *FastSemaphore {
31 ch := make(chan struct{}, capacity)
32 // Pre-fill with tokens
33 for i := int32(0); i < capacity; i++ {
34 ch <- struct{}{}
35 }
36 return &FastSemaphore{
37 tokens: ch,
38 max: capacity,
39 }
40}
41
42// TryAcquire attempts to acquire a token without blocking.
43// Returns true if successful, false if no tokens available.

Callers 2

NewReAuthPoolHookFunction · 0.92
NewConnPoolFunction · 0.92

Calls

no outgoing calls

Tested by

no test coverage detected