Add mutex lock within Add function
This commit is contained in:
parent
f50cbdf595
commit
0cf4a5dc48
1 changed files with 4 additions and 5 deletions
|
@ -44,9 +44,6 @@ func New(info ProgressInfo) *ProgressBar {
|
|||
|
||||
func (p *ProgressBar) render(final bool) {
|
||||
|
||||
p.lock.Lock()
|
||||
defer p.lock.Unlock()
|
||||
|
||||
var sb strings.Builder
|
||||
|
||||
numFilled := math.Round((float64(p.currentBytes) / float64(p.maxBytes)) * 40)
|
||||
|
@ -121,7 +118,7 @@ func (p *ProgressBar) render(final bool) {
|
|||
if width == 0 {
|
||||
lineNum = 1
|
||||
} else {
|
||||
lineNum = ((len(removeANSIEscapeCodes(sb.String())) + width - 1) / width)
|
||||
lineNum = (len(removeANSIEscapeCodes(sb.String())) + width - 1) / width
|
||||
}
|
||||
|
||||
if p.hasStarted {
|
||||
|
@ -142,9 +139,11 @@ func (p *ProgressBar) render(final bool) {
|
|||
}
|
||||
|
||||
func (p *ProgressBar) Add(num int64) {
|
||||
p.lock.Lock()
|
||||
p.currentBytes = p.currentBytes + num
|
||||
|
||||
p.render(false)
|
||||
p.lock.Unlock()
|
||||
}
|
||||
|
||||
func (p *ProgressBar) Close() (err error) {
|
||||
|
@ -161,7 +160,7 @@ func (p *ProgressBar) Close() (err error) {
|
|||
if width == 0 {
|
||||
lineNum = 1
|
||||
} else {
|
||||
lineNum = ((p.textWidth + width - 1) / width)
|
||||
lineNum = (p.textWidth + width - 1) / width
|
||||
}
|
||||
|
||||
for i := 0; i < lineNum; i++ {
|
||||
|
|
Loading…
Reference in a new issue