removed requirement for Show() method call

This commit is contained in:
milarin 2023-03-10 22:22:56 +01:00
parent acfe7532d1
commit 5cb77ec486

10
view.go
View File

@ -40,10 +40,7 @@ func NewForWriter[K comparable](w io.Writer) *View[K] {
} }
func (v *View[K]) Show() { func (v *View[K]) Show() {
go func() { go v.WaitForAllTasks()
defer close(v.reportCh)
v.wg.Wait()
}()
for status := range v.reportCh { for status := range v.reportCh {
v.lastReports[status.ID] = status v.lastReports[status.ID] = status
@ -83,5 +80,10 @@ func (v *View[K]) Done(task K) {
} }
func (v *View[K]) WaitForAllTasks() { func (v *View[K]) WaitForAllTasks() {
go func() {
defer close(v.reportCh)
v.wg.Wait()
}()
<-v.doneCh <-v.doneCh
} }