NewFastSemaphore creates a new fast semaphore with the given capacity.
(capacity int32)
| 28 | |
| 29 | // NewFastSemaphore creates a new fast semaphore with the given capacity. |
| 30 | func 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. |
no outgoing calls
no test coverage detected