@@ -23,37 +23,38 @@ var (
23
23
24
24
// Progress helps track progress for one or more tasks.
25
25
type Progress struct {
26
- autoStop bool
27
- lengthMessage int
28
- lengthProgress int
29
- lengthProgressOverall int
30
- lengthTracker int
31
- logsToRender []string
32
- logsToRenderMutex sync.RWMutex
33
- numTrackersExpected int64
34
- outputWriter io.Writer
35
- overallTracker * Tracker
36
- overallTrackerMutex sync.RWMutex
37
- pinnedMessages []string
38
- pinnedMessageMutex sync.RWMutex
39
- pinnedMessageNumLines int
40
- renderContext context.Context
41
- renderContextCancel context.CancelFunc
42
- renderInProgress bool
43
- renderInProgressMutex sync.RWMutex
44
- sortBy SortBy
45
- style * Style
46
- terminalWidth int
47
- terminalWidthMutex sync.RWMutex
48
- terminalWidthOverride int
49
- trackerPosition Position
50
- trackersActive []* Tracker
51
- trackersActiveMutex sync.RWMutex
52
- trackersDone []* Tracker
53
- trackersDoneMutex sync.RWMutex
54
- trackersInQueue []* Tracker
55
- trackersInQueueMutex sync.RWMutex
56
- updateFrequency time.Duration
26
+ autoStop bool
27
+ lengthMessage int
28
+ lengthProgress int
29
+ lengthProgressOverall int
30
+ lengthTracker int
31
+ logsToRender []string
32
+ logsToRenderMutex sync.RWMutex
33
+ numTrackersExpected int64
34
+ outputWriter io.Writer
35
+ overallTracker * Tracker
36
+ overallTrackerMutex sync.RWMutex
37
+ pinnedMessages []string
38
+ pinnedMessageMutex sync.RWMutex
39
+ pinnedMessageNumLines int
40
+ renderContext context.Context
41
+ renderContextCancel context.CancelFunc
42
+ renderContextCancelMutex sync.Mutex
43
+ renderInProgress bool
44
+ renderInProgressMutex sync.RWMutex
45
+ sortBy SortBy
46
+ style * Style
47
+ terminalWidth int
48
+ terminalWidthMutex sync.RWMutex
49
+ terminalWidthOverride int
50
+ trackerPosition Position
51
+ trackersActive []* Tracker
52
+ trackersActiveMutex sync.RWMutex
53
+ trackersDone []* Tracker
54
+ trackersDoneMutex sync.RWMutex
55
+ trackersInQueue []* Tracker
56
+ trackersInQueueMutex sync.RWMutex
57
+ updateFrequency time.Duration
57
58
}
58
59
59
60
// Position defines the position of the Tracker with respect to the Tracker's
@@ -284,7 +285,10 @@ func (p *Progress) ShowValue(show bool) {
284
285
285
286
// Stop stops the Render() logic that is in progress.
286
287
func (p * Progress ) Stop () {
287
- if p .IsRenderInProgress () {
288
+ p .renderContextCancelMutex .Lock ()
289
+ defer p .renderContextCancelMutex .Unlock ()
290
+
291
+ if p .renderContextCancel != nil {
288
292
p .renderContextCancel ()
289
293
}
290
294
}
@@ -309,15 +313,17 @@ func (p *Progress) getTerminalWidth() int {
309
313
}
310
314
311
315
func (p * Progress ) initForRender () {
316
+ // reset the signals
317
+ p .renderContextCancelMutex .Lock ()
318
+ p .renderContext , p .renderContextCancel = context .WithCancel (context .Background ())
319
+ p .renderContextCancelMutex .Unlock ()
320
+
312
321
// pick a default style
313
322
p .Style ()
314
323
if p .style .Options .SpeedOverallFormatter == nil {
315
324
p .style .Options .SpeedOverallFormatter = FormatNumber
316
325
}
317
326
318
- // reset the signals
319
- p .renderContext , p .renderContextCancel = context .WithCancel (context .Background ())
320
-
321
327
// pick default lengths if no valid ones set
322
328
if p .lengthTracker <= 0 {
323
329
p .lengthTracker = DefaultLengthTracker
0 commit comments