milvus/internal/proxynode/condition.go
cai.zhang aa5ecbdc02 Use the project log instead of standard log of proxyservice and proxynode
Signed-off-by: cai.zhang <cai.zhang@zilliz.com>
2021-03-08 19:39:36 +08:00

44 lines
646 B
Go

package proxynode
import (
"context"
"errors"
)
type Condition interface {
WaitToFinish() error
Notify(err error)
Ctx() context.Context
}
type TaskCondition struct {
done chan error
ctx context.Context
}
func (tc *TaskCondition) WaitToFinish() error {
for {
select {
case <-tc.ctx.Done():
return errors.New("timeout")
case err := <-tc.done:
return err
}
}
}
func (tc *TaskCondition) Notify(err error) {
tc.done <- err
}
func (tc *TaskCondition) Ctx() context.Context {
return tc.ctx
}
func NewTaskCondition(ctx context.Context) *TaskCondition {
return &TaskCondition{
done: make(chan error),
ctx: ctx,
}
}