Skip to content

Commit

Permalink
fix: Acquire lock when printing text to fix race condition
Browse files Browse the repository at this point in the history
  • Loading branch information
gabe565 committed Sep 15, 2024
1 parent 03fc4e9 commit ffc015d
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions progressbar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,8 @@ func shouldCacheOutput(pb *ProgressBar) bool {
}

func Bprintln(pb *ProgressBar, a ...interface{}) (int, error) {
pb.lock.Lock()
defer pb.lock.Unlock()
if !shouldCacheOutput(pb) {
return fmt.Fprintln(pb.config.writer, a...)
} else {
Expand All @@ -1161,6 +1163,8 @@ func Bprintln(pb *ProgressBar, a ...interface{}) (int, error) {
}

func Bprintf(pb *ProgressBar, format string, a ...interface{}) (int, error) {
pb.lock.Lock()
defer pb.lock.Unlock()
if !shouldCacheOutput(pb) {
return fmt.Fprintf(pb.config.writer, format, a...)
} else {
Expand Down

0 comments on commit ffc015d

Please sign in to comment.