IsRunning: no need to occupy b.operateState
Vladimir Bauer
1 year, 10 months ago
| 370 | 370 | } |
| 371 | 371 | } |
| 372 | 372 | |
| 373 | // IsRunning reports whether the bar is running, i.e. not yet completed | |
| 374 | // and not yet aborted. | |
| 373 | // IsRunning reports whether the bar is in running state. | |
| 375 | 374 | func (b *Bar) IsRunning() bool { |
| 376 | result := make(chan bool) | |
| 377 | select { | |
| 378 | case b.operateState <- func(s *bState) { result <- !s.completed && !s.aborted }: | |
| 379 | return <-result | |
| 380 | case <-b.done: | |
| 375 | select { | |
| 376 | case <-b.ctx.Done(): | |
| 381 | 377 | return false |
| 378 | default: | |
| 379 | return true | |
| 382 | 380 | } |
| 383 | 381 | } |
| 384 | 382 |