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

Function asyncControllable

interpreter/async_test.go:529–550  ·  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

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

Calls 1

AddMethod · 0.65

Tested by

no test coverage detected