TryAcquire attempts to acquire a concurrency slot and increments the active calls count.
()
| 479 | |
| 480 | // TryAcquire attempts to acquire a concurrency slot and increments the active calls count. |
| 481 | func (g *asyncGate) TryAcquire() bool { |
| 482 | if g == nil { |
| 483 | return true |
| 484 | } |
| 485 | if g.semaphore != nil { |
| 486 | select { |
| 487 | case g.semaphore <- struct{}{}: |
| 488 | default: |
| 489 | return false |
| 490 | } |
| 491 | } |
| 492 | g.activeCalls.Add(1) |
| 493 | return true |
| 494 | } |
| 495 | |
| 496 | // Release releases a concurrency slot and decrements the active calls count (used for defensive recovery). |
| 497 | func (g *asyncGate) Release() { |