idleBackoff returns how long a worker should sleep after n consecutive no-work polls. The wake channel is selected against this timer so any new TX (kick) cancels the sleep immediately and any held server-side long-poll receives downstream chunks without needing a fresh poll — so even a 1s tail does
(n int)
| 656 | // long-poll receives downstream chunks without needing a fresh poll — |
| 657 | // so even a 1s tail does not add user-visible latency. |
| 658 | func idleBackoff(n int) time.Duration { |
| 659 | switch { |
| 660 | case n < 3: |
| 661 | return pollIdleSleep |
| 662 | case n < 10: |
| 663 | return 50 * time.Millisecond |
| 664 | case n < 30: |
| 665 | return 250 * time.Millisecond |
| 666 | default: |
| 667 | return time.Second |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | // pollOnce drains pending tx frames, POSTs them as a batch, and routes any |
| 672 | // response frames back to their sessions. Returns true if any work was done |
no outgoing calls