diff options
author | Daniel Milde <daniel@milde.cz> | 2021-03-22 00:22:59 +0100 |
---|---|---|
committer | Daniel Milde <daniel@milde.cz> | 2021-03-25 18:50:01 +0100 |
commit | e8c204221c7282917a7733457451269ac939068e (patch) | |
tree | 2d8659ccd418fdd50653528ce49ea69f56959d8c /stdout | |
parent | 15fc8e7018c7157f7d6e9b158047d5be0baa9658 (diff) |
use channel instead of mutex
Diffstat (limited to 'stdout')
-rw-r--r-- | stdout/stdout.go | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/stdout/stdout.go b/stdout/stdout.go index 647e243..8d728fe 100644 --- a/stdout/stdout.go +++ b/stdout/stdout.go @@ -202,15 +202,18 @@ func (ui *UI) updateProgress() { progressRunes := []rune(`⠇⠏⠋⠙⠹⠸⠼⠴⠦⠧`) - progress := ui.analyzer.GetProgress() + progressChan := ui.analyzer.GetProgressChan() + doneChan := ui.analyzer.GetDoneChan() + + var progress analyze.CurrentProgress i := 0 for { - progress.Mutex.Lock() - fmt.Fprint(ui.output, emptyRow) - if progress.Done { + select { + case progress = <-progressChan: + case <-doneChan: fmt.Fprint(ui.output, "\r") return } @@ -221,7 +224,6 @@ func (ui *UI) updateProgress() { ui.red.Sprint(progress.ItemCount)+ " size: "+ ui.formatSize(progress.TotalSize)) - progress.Mutex.Unlock() time.Sleep(100 * time.Millisecond) i++ |