mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
Fix race in Progress shutdown where some messages could have been lost.
This commit is contained in:
+4
-6
@@ -12,6 +12,7 @@ const (
|
|||||||
codePrint = iota
|
codePrint = iota
|
||||||
codeProgress
|
codeProgress
|
||||||
codeHideProgress
|
codeHideProgress
|
||||||
|
codeStop
|
||||||
)
|
)
|
||||||
|
|
||||||
type printTask struct {
|
type printTask struct {
|
||||||
@@ -37,7 +38,6 @@ var (
|
|||||||
// NewProgress creates new progress instance
|
// NewProgress creates new progress instance
|
||||||
func NewProgress() *Progress {
|
func NewProgress() *Progress {
|
||||||
return &Progress{
|
return &Progress{
|
||||||
stop: make(chan bool),
|
|
||||||
stopped: make(chan bool),
|
stopped: make(chan bool),
|
||||||
queue: make(chan printTask, 100),
|
queue: make(chan printTask, 100),
|
||||||
}
|
}
|
||||||
@@ -51,7 +51,7 @@ func (p *Progress) Start() {
|
|||||||
// Shutdown shuts down progress display
|
// Shutdown shuts down progress display
|
||||||
func (p *Progress) Shutdown() {
|
func (p *Progress) Shutdown() {
|
||||||
p.ShutdownBar()
|
p.ShutdownBar()
|
||||||
p.stop <- true
|
p.queue <- printTask{code: codeStop}
|
||||||
<-p.stopped
|
<-p.stopped
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -136,8 +136,7 @@ func (p *Progress) ColoredPrintf(msg string, a ...interface{}) {
|
|||||||
|
|
||||||
func (p *Progress) worker() {
|
func (p *Progress) worker() {
|
||||||
for {
|
for {
|
||||||
select {
|
task := <-p.queue
|
||||||
case task := <-p.queue:
|
|
||||||
switch task.code {
|
switch task.code {
|
||||||
case codePrint:
|
case codePrint:
|
||||||
if p.barShown {
|
if p.barShown {
|
||||||
@@ -155,8 +154,7 @@ func (p *Progress) worker() {
|
|||||||
fmt.Print("\r\033[2K")
|
fmt.Print("\r\033[2K")
|
||||||
p.barShown = false
|
p.barShown = false
|
||||||
}
|
}
|
||||||
}
|
case codeStop:
|
||||||
case <-p.stop:
|
|
||||||
p.stopped <- true
|
p.stopped <- true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user