complete with timeout
Vladimir Bauer
9 years ago
| 27 | 27 | |
| 28 | 28 | // Bar represents a progress Bar |
| 29 | 29 | type Bar struct { |
| 30 | incrCh chan incrReq | |
| 31 | 30 | completeReqCh chan struct{} |
| 32 | 31 | done chan struct{} |
| 33 | 32 | inProgress chan struct{} |
| 38 | 37 | state state |
| 39 | 38 | } |
| 40 | 39 | |
| 41 | // Refil is a struct for b.IncrWithReFill | |
| 42 | type refill struct { | |
| 43 | char rune | |
| 44 | till int64 | |
| 45 | } | |
| 46 | ||
| 47 | 40 | type ( |
| 48 | incrReq struct { | |
| 49 | amount int64 | |
| 50 | refill *refill | |
| 41 | refill struct { | |
| 42 | char rune | |
| 43 | till int64 | |
| 51 | 44 | } |
| 52 | 45 | state struct { |
| 53 | 46 | id int |
| 86 | 79 | } |
| 87 | 80 | |
| 88 | 81 | b := &Bar{ |
| 89 | incrCh: make(chan incrReq), | |
| 90 | 82 | completeReqCh: make(chan struct{}), |
| 91 | 83 | done: make(chan struct{}), |
| 92 | 84 | inProgress: make(chan struct{}), |
| 228 | 220 | b.Complete() |
| 229 | 221 | } |
| 230 | 222 | }: |
| 231 | default: | |
| 223 | case <-time.After(prr): | |
| 224 | return | |
| 232 | 225 | } |
| 233 | 226 | } |
| 234 | 227 | |