milvus/internal/util/cgo/options.go
chyezh f53ab54c5d
enhance: async cgo utility (#33133)
issue: #30926, #33132

- implement future-based cgo utility.

---------

Signed-off-by: chyezh <chyezh@outlook.com>
2024-06-09 22:55:53 +08:00

33 lines
591 B
Go

package cgo
func getDefaultOpt() *options {
return &options{
name: "unknown",
releaser: nil,
}
}
type options struct {
name string
releaser func()
}
// Opt is the option type for future.
type Opt func(*options)
// WithReleaser sets the releaser function.
// When a future is ready, the releaser function will be called once.
func WithReleaser(releaser func()) Opt {
return func(o *options) {
o.releaser = releaser
}
}
// WithName sets the name of the future.
// Only used for metrics.
func WithName(name string) Opt {
return func(o *options) {
o.name = name
}
}