2021-01-15 14:38:36 +08:00
|
|
|
package proxynode
|
2020-11-17 20:00:23 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/zilliztech/milvus-distributed/internal/errors"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Condition interface {
|
|
|
|
WaitToFinish() error
|
|
|
|
Notify(err error)
|
2021-02-03 17:30:10 +08:00
|
|
|
Ctx() context.Context
|
2020-11-17 20:00:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2021-02-03 17:30:10 +08:00
|
|
|
func (tc *TaskCondition) Ctx() context.Context {
|
|
|
|
return tc.ctx
|
|
|
|
}
|
|
|
|
|
2020-11-17 20:00:23 +08:00
|
|
|
func NewTaskCondition(ctx context.Context) *TaskCondition {
|
|
|
|
return &TaskCondition{
|
|
|
|
done: make(chan error),
|
|
|
|
ctx: ctx,
|
|
|
|
}
|
|
|
|
}
|