Progress during publishing.

This commit is contained in:
Andrey Smirnov
2014-03-07 17:24:45 +04:00
parent 1571a3331d
commit c55733fc05
15 changed files with 66 additions and 11 deletions

View File

@@ -13,11 +13,13 @@ const (
codeProgress
codeHideProgress
codeStop
codeFlush
)
type printTask struct {
code int
message string
reply chan bool
}
// Progress is a progress displaying subroutine, it allows to show download and other operations progress
@@ -55,6 +57,13 @@ func (p *Progress) Shutdown() {
<-p.stopped
}
// Flush waits for all queued messages to be displayed
func (p *Progress) Flush() {
ch := make(chan bool)
p.queue <- printTask{code: codeFlush, reply: ch}
<-ch
}
// InitBar starts progressbar for count bytes or count items
func (p *Progress) InitBar(count int64, isBytes bool) {
if p.bar != nil {
@@ -161,6 +170,8 @@ func (p *Progress) worker() {
fmt.Print("\r\033[2K")
p.barShown = false
}
case codeFlush:
task.reply <- true
case codeStop:
p.stopped <- true
return