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

Function SingletonAsyncBinding

common/decls/decls.go:586–602  ·  view source on GitHub ↗

SingletonAsyncBinding creates a singleton async function definition to be used with all function overloads. The provided function is called in its own goroutine with the provided context. The function should block until the result is available, and the framework manages goroutine and channel lifecyc

(fn functions.BlockingAsyncOp, traits ...int)

Source from the content-addressed store, hash-verified

584// Note, this approach works well if operand is expected to have a specific trait which it implements,
585// e.g. traits.ContainerType. Otherwise, prefer per-overload async bindings.
586func SingletonAsyncBinding(fn functions.BlockingAsyncOp, traits ...int) FunctionOpt {
587 trait := 0
588 for _, t := range traits {
589 trait = trait | t
590 }
591 return func(f *FunctionDecl) (*FunctionDecl, error) {
592 if f.singleton != nil {
593 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
594 }
595 f.singleton = &functions.Overload{
596 Operator: f.Name(),
597 Async: wrapAsyncOp(fn),
598 OperandTrait: trait,
599 }
600 return f, nil
601 }
602}
603
604// Overload defines a new global overload with an overload id, argument types, and result type. Through the
605// use of OverloadOpt options, the overload may also be configured with a binding, an operand trait, and to

Callers 3

SingletonAsyncBindingFunction · 0.92

Calls 2

wrapAsyncOpFunction · 0.85
NameMethod · 0.65

Tested by 2