Codebase list golang-github-vbauerster-mpb / e387127
introduce ErrCallAfterStop error Vladimir Bauer 9 years ago
1 changed file(s) with 24 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
00 package mpb
11
22 import (
3 "errors"
34 "fmt"
45 "io"
56 "os"
910
1011 "github.com/vbauerster/mpb/cwriter"
1112 )
13
14 var ErrCallAfterStop = errors.New("method call on stopped Progress instance")
1215
1316 type opType uint
1417
7477 return p
7578 }
7679
77 // SetOut sets underlying writer of progress
78 // default is os.Stdout
80 // SetOut sets underlying writer of progress. Default is os.Stdout
81 // pancis, if called on stopped Progress instance, i.e after Stop()
7982 func (p *Progress) SetOut(w io.Writer) *Progress {
83 if p.isAllDone() {
84 panic(ErrCallAfterStop)
85 }
8086 if w == nil {
8187 return p
8288 }
8591 }
8692
8793 // RefreshRate overrides default (30ms) refreshRate value
94 // pancis, if called on stopped Progress instance, i.e after Stop()
8895 func (p *Progress) RefreshRate(d time.Duration) *Progress {
96 if p.isAllDone() {
97 panic(ErrCallAfterStop)
98 }
8999 p.rrChangeReqCh <- d
90100 return p
91101 }
97107 }
98108
99109 // AddBar creates a new progress bar and adds to the container
110 // pancis, if called on stopped Progress instance, i.e after Stop()
100111 func (p *Progress) AddBar(total int) *Bar {
112 if p.isAllDone() {
113 panic(ErrCallAfterStop)
114 }
101115 result := make(chan bool)
102116 bar := newBar(total, p.width, p.wg)
103117 p.op <- &operation{opBarAdd, bar, result}
108122 }
109123
110124 // RemoveBar removes bar at any time
125 // pancis, if called on stopped Progress instance, i.e after Stop()
111126 func (p *Progress) RemoveBar(b *Bar) bool {
127 if p.isAllDone() {
128 panic(ErrCallAfterStop)
129 }
112130 result := make(chan bool)
113131 p.op <- &operation{opBarRemove, b, result}
114132 return <-result
115133 }
116134
117135 // BarsCount returns bars count in the container
136 // pancis, if called on stopped Progress instance, i.e after Stop()
118137 func (p *Progress) BarsCount() int {
138 if p.isAllDone() {
139 panic(ErrCallAfterStop)
140 }
119141 respCh := make(chan int)
120142 p.countReqCh <- respCh
121143 return <-respCh