fixed implementation of WaitForAllTasks
This commit is contained in:
parent
132a2a4200
commit
3cb1984024
6
view.go
6
view.go
@ -19,6 +19,7 @@ type View[K comparable] struct {
|
|||||||
|
|
||||||
wg *sync.WaitGroup
|
wg *sync.WaitGroup
|
||||||
reportCh chan report[K]
|
reportCh chan report[K]
|
||||||
|
doneCh chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func New[K comparable]() *View[K] {
|
func New[K comparable]() *View[K] {
|
||||||
@ -32,6 +33,7 @@ func NewForWriter[K comparable](w io.Writer) *View[K] {
|
|||||||
taskMap: map[K]struct{}{},
|
taskMap: map[K]struct{}{},
|
||||||
|
|
||||||
reportCh: make(chan report[K], 100),
|
reportCh: make(chan report[K], 100),
|
||||||
|
doneCh: make(chan struct{}),
|
||||||
lastReports: map[K]report[K]{},
|
lastReports: map[K]report[K]{},
|
||||||
wg: &sync.WaitGroup{},
|
wg: &sync.WaitGroup{},
|
||||||
}
|
}
|
||||||
@ -48,6 +50,8 @@ func (v *View[K]) Show() {
|
|||||||
v.Add(status.ID)
|
v.Add(status.ID)
|
||||||
v.print()
|
v.print()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
v.doneCh <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v *View[K]) SortFunc(f func(i, j K) bool) {
|
func (v *View[K]) SortFunc(f func(i, j K) bool) {
|
||||||
@ -79,5 +83,5 @@ func (v *View[K]) Done(task K) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (v *View[K]) WaitForAllTasks() {
|
func (v *View[K]) WaitForAllTasks() {
|
||||||
v.wg.Wait()
|
<-v.doneCh
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user