Skip to content

Commit

Permalink
fix: remove the lock in progressbar (#1569)
Browse files Browse the repository at this point in the history
Signed-off-by: Keming <[email protected]>
  • Loading branch information
kemingy authored Apr 22, 2023
1 parent e56981a commit ac0dd7e
Showing 1 changed file with 0 additions and 10 deletions.
10 changes: 0 additions & 10 deletions pkg/envd/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package envd

import (
"fmt"
"sync"
"time"

"github.com/schollz/progressbar/v3"
Expand Down Expand Up @@ -78,7 +77,6 @@ type ProgressBar struct {
currStage int
totalStage int
notify chan struct{}
lock *sync.Mutex
}

func InitProgressBar(stage int) *ProgressBar {
Expand All @@ -90,7 +88,6 @@ func InitProgressBar(stage int) *ProgressBar {
fmt.Println()
}),
)
var lock sync.Mutex

go func() {
timer := time.NewTicker(time.Millisecond * 100)
Expand All @@ -99,9 +96,7 @@ func InitProgressBar(stage int) *ProgressBar {
case <-done:
return
case <-timer.C:
lock.Lock()
_ = bar.Add(1)
lock.Unlock()
}
}
}()
Expand All @@ -110,14 +105,11 @@ func InitProgressBar(stage int) *ProgressBar {
notify: done,
bar: bar,
totalStage: stage,
lock: &lock,
}
return &b
}

func (b *ProgressBar) updateTitle(title string) {
b.lock.Lock()
defer b.lock.Unlock()
b.currStage += 1
b.bar.Describe(fmt.Sprintf("[cyan][%d/%d][reset] %s",
b.currStage,
Expand All @@ -127,8 +119,6 @@ func (b *ProgressBar) updateTitle(title string) {
}

func (b *ProgressBar) finish() {
b.lock.Lock()
defer b.lock.Unlock()
b.notify <- struct{}{}
if err := b.bar.Finish(); err != nil {
logrus.Infof("stop progress bar err: %v\n", err)
Expand Down

0 comments on commit ac0dd7e

Please sign in to comment.