MCPcopy Create free account
hub / github.com/cel-expr/cel-go / asyncControllable

Function asyncControllable

interpreter/async_test.go:452–473  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
452func 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
475func TestLaunchAdmissionAndBounding(t *testing.T) {
476 ctx, cancel := context.WithCancel(context.Background())

Calls 1

AddMethod · 0.65

Tested by

no test coverage detected