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)
| 450 | // asyncControllable returns a channel-based AsyncOp whose calls block until release is closed, |
| 451 | // tracking the number of concurrently live calls and the high-water mark. |
| 452 | func asyncControllable(release <-chan struct{}, live, maxLive *atomic.Int32) functions.AsyncOp { |
| 453 | return func(ctx context.Context, args ...ref.Val) <-chan ref.Val { |
| 454 | ch := make(chan ref.Val, 1) |
| 455 | go func() { |
| 456 | cur := live.Add(1) |
| 457 | for { |
| 458 | old := maxLive.Load() |
| 459 | if cur <= old || maxLive.CompareAndSwap(old, cur) { |
| 460 | break |
| 461 | } |
| 462 | } |
| 463 | select { |
| 464 | case <-release: |
| 465 | case <-ctx.Done(): |
| 466 | } |
| 467 | live.Add(-1) |
| 468 | ch <- args[0] |
| 469 | close(ch) |
| 470 | }() |
| 471 | return ch |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | func TestLaunchAdmissionAndBounding(t *testing.T) { |
| 476 | ctx, cancel := context.WithCancel(context.Background()) |
no test coverage detected