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