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)
| 563 | // Note, this approach works well if operand is expected to have a specific trait which it implements, |
| 564 | // e.g. traits.ContainerType. Otherwise, prefer per-overload async bindings. |
| 565 | func SingletonAsyncBinding(fn functions.BlockingAsyncOp, traits ...int) FunctionOpt { |
| 566 | trait := 0 |
| 567 | for _, t := range traits { |
| 568 | trait = trait | t |
| 569 | } |
| 570 | return func(f *FunctionDecl) (*FunctionDecl, error) { |
| 571 | if f.singleton != nil { |
| 572 | return nil, fmt.Errorf("function already has a singleton binding: %s", f.Name()) |
| 573 | } |
| 574 | f.singleton = &functions.Overload{ |
| 575 | Operator: f.Name(), |
| 576 | Async: wrapAsyncOp(fn), |
| 577 | OperandTrait: trait, |
| 578 | } |
| 579 | return f, nil |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | // Overload defines a new global overload with an overload id, argument types, and result type. Through the |
| 584 | // use of OverloadOpt options, the overload may also be configured with a binding, an operand trait, and to |