asyncControllable returns a channel-based AsyncOp whose calls block until release is closed, tracking the number of concurrently live calls and the high-water mark.
(release <-chan struct{}, live, maxLive *atomic.Int32)
| 527 | // asyncControllable returns a channel-based AsyncOp whose calls block until release is closed, |
| 528 | // tracking the number of concurrently live calls and the high-water mark. |
| 529 | func asyncControllable(release <-chan struct{}, live, maxLive *atomic.Int32) functions.AsyncOp { |
| 530 | return func(ctx context.Context, args ...ref.Val) <-chan ref.Val { |
| 531 | ch := make(chan ref.Val, 1) |
| 532 | go func() { |
| 533 | cur := live.Add(1) |
| 534 | for { |
| 535 | old := maxLive.Load() |
| 536 | if cur <= old || maxLive.CompareAndSwap(old, cur) { |
| 537 | break |
| 538 | } |
| 539 | } |
| 540 | select { |
| 541 | case <-release: |
| 542 | case <-ctx.Done(): |
| 543 | } |
| 544 | live.Add(-1) |
| 545 | ch <- args[0] |
| 546 | close(ch) |
| 547 | }() |
| 548 | return ch |
| 549 | } |
| 550 | } |
| 551 | |
| 552 | func TestLaunchAdmissionAndBounding(t *testing.T) { |
| 553 | ctx, cancel := context.WithCancel(context.Background()) |
no test coverage detected