mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #458 from yifan-gu/close_chan
Changed op.notify<-true to close(op.notify).
This commit is contained in:
commit
e659688f6d
@ -34,7 +34,7 @@ type Operation struct {
|
|||||||
awaiting <-chan interface{}
|
awaiting <-chan interface{}
|
||||||
finished *time.Time
|
finished *time.Time
|
||||||
lock sync.Mutex
|
lock sync.Mutex
|
||||||
notify chan bool
|
notify chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Operations tracks all the ongoing operations.
|
// Operations tracks all the ongoing operations.
|
||||||
@ -62,7 +62,7 @@ func (ops *Operations) NewOperation(from <-chan interface{}) *Operation {
|
|||||||
op := &Operation{
|
op := &Operation{
|
||||||
ID: strconv.FormatInt(id, 10),
|
ID: strconv.FormatInt(id, 10),
|
||||||
awaiting: from,
|
awaiting: from,
|
||||||
notify: make(chan bool, 1),
|
notify: make(chan struct{}),
|
||||||
}
|
}
|
||||||
go op.wait()
|
go op.wait()
|
||||||
go ops.insert(op)
|
go ops.insert(op)
|
||||||
@ -128,7 +128,7 @@ func (op *Operation) wait() {
|
|||||||
op.result = result
|
op.result = result
|
||||||
finished := time.Now()
|
finished := time.Now()
|
||||||
op.finished = &finished
|
op.finished = &finished
|
||||||
op.notify <- true
|
close(op.notify)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WaitFor waits for the specified duration, or until the operation finishes,
|
// WaitFor waits for the specified duration, or until the operation finishes,
|
||||||
@ -137,9 +137,6 @@ func (op *Operation) WaitFor(timeout time.Duration) {
|
|||||||
select {
|
select {
|
||||||
case <-time.After(timeout):
|
case <-time.After(timeout):
|
||||||
case <-op.notify:
|
case <-op.notify:
|
||||||
// Re-send on this channel in case there are others
|
|
||||||
// waiting for notification.
|
|
||||||
op.notify <- true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user