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

Function SingletonAsyncBinding

common/decls/decls.go:555–571  ·  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

553// Note, this approach works well if operand is expected to have a specific trait which it implements,
554// e.g. traits.ContainerType. Otherwise, prefer per-overload async bindings.
555func SingletonAsyncBinding(fn functions.BlockingAsyncOp, traits ...int) FunctionOpt {
556 trait := 0
557 for _, t := range traits {
558 trait = trait | t
559 }
560 return func(f *FunctionDecl) (*FunctionDecl, error) {
561 if f.singleton != nil {
562 return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name())
563 }
564 f.singleton = &functions.Overload{
565 Operator: f.Name(),
566 Async: wrapAsyncOp(fn),
567 OperandTrait: trait,
568 }
569 return f, nil
570 }
571}
572
573// Overload defines a new global overload with an overload id, argument types, and result type. Through the
574// 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