mirror of
https://gitee.com/milvus-io/milvus.git
synced 2024-12-02 03:48:37 +08:00
3563136c2a
issue: #33285 - optimize the message package - add interceptor package to achieve append operation intercepting. - add timetick interceptor to attach timetick properties for message. - add timetick background task to send timetick message. Signed-off-by: chyezh <chyezh@outlook.com>
42 lines
774 B
Go
42 lines
774 B
Go
package syncutil
|
|
|
|
// Future is a future value that can be set and retrieved.
|
|
type Future[T any] struct {
|
|
ch chan struct{}
|
|
value T
|
|
}
|
|
|
|
// NewFuture creates a new future.
|
|
func NewFuture[T any]() *Future[T] {
|
|
return &Future[T]{
|
|
ch: make(chan struct{}),
|
|
}
|
|
}
|
|
|
|
// Set sets the value of the future.
|
|
func (f *Future[T]) Set(value T) {
|
|
f.value = value
|
|
close(f.ch)
|
|
}
|
|
|
|
// Get retrieves the value of the future if set, otherwise block until set.
|
|
func (f *Future[T]) Get() T {
|
|
<-f.ch
|
|
return f.value
|
|
}
|
|
|
|
// Done returns a channel that is closed when the future is set.
|
|
func (f *Future[T]) Done() <-chan struct{} {
|
|
return f.ch
|
|
}
|
|
|
|
// Ready returns true if the future is set.
|
|
func (f *Future[T]) Ready() bool {
|
|
select {
|
|
case <-f.ch:
|
|
return true
|
|
default:
|
|
return false
|
|
}
|
|
}
|