AsyncBinding provides the implementation of an asynchronous overload. 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 lifecycle. This follows the same pattern use
(fn functions.BlockingAsyncOp)
| 966 | // This follows the same pattern used by gRPC-Go and other major Go frameworks where user |
| 967 | // code is synchronous and the framework manages concurrency. |
| 968 | func AsyncBinding(fn functions.BlockingAsyncOp) OverloadOpt { |
| 969 | return func(o *OverloadDecl) (*OverloadDecl, error) { |
| 970 | if o.HasBinding() { |
| 971 | return nil, fmt.Errorf("overload already has a binding: %s", o.ID()) |
| 972 | } |
| 973 | if o.hasLateBinding { |
| 974 | return nil, fmt.Errorf("overload already has a late binding: %s", o.ID()) |
| 975 | } |
| 976 | o.asyncOp = wrapAsyncOp(fn) |
| 977 | return o, nil |
| 978 | } |
| 979 | } |
| 980 | |
| 981 | // wrapAsyncOp adapts a blocking function into the channel-based AsyncOp used internally. |
| 982 | // |