add sync param to BarQueueAfter option
Vladimir Bauer
4 years ago
| 57 | 57 |
extender extenderFunc
|
| 58 | 58 |
debugOut io.Writer
|
| 59 | 59 |
|
| 60 | |
// afterBar is a key for (*pState).queueBars
|
| 61 | |
afterBar *Bar
|
|
60 |
afterBar *Bar // key for (*pState).queueBars
|
|
61 |
sync bool
|
| 62 | 62 |
}
|
| 63 | 63 |
|
| 64 | 64 |
type frame struct {
|
|
| 299 | 299 |
|
| 300 | 300 |
func (b *Bar) serve(ctx context.Context, bs *bState) {
|
| 301 | 301 |
defer b.container.bwg.Done()
|
|
302 |
if bs.afterBar != nil && bs.sync {
|
|
303 |
<-bs.afterBar.done
|
|
304 |
}
|
| 302 | 305 |
for {
|
| 303 | 306 |
select {
|
| 304 | 307 |
case op := <-b.operateState:
|
| 59 | 59 |
}
|
| 60 | 60 |
|
| 61 | 61 |
// BarQueueAfter puts this (being constructed) bar into the queue.
|
| 62 | |
// Queued bar will run after argument bar completes, replacing its
|
| 63 | |
// place. While bar is queued all of its methods are blocked.
|
| 64 | |
func BarQueueAfter(bar *Bar) BarOption {
|
|
62 |
// When argument bar completes or aborts queued bar replaces its place.
|
|
63 |
// If sync is true queued bar is suspended until argument bar completes
|
|
64 |
// or aborts.
|
|
65 |
func BarQueueAfter(bar *Bar, sync bool) BarOption {
|
| 65 | 66 |
if bar == nil {
|
| 66 | 67 |
return nil
|
| 67 | 68 |
}
|
| 68 | 69 |
return func(s *bState) {
|
| 69 | 70 |
s.afterBar = bar
|
|
71 |
s.sync = sync
|
| 70 | 72 |
}
|
| 71 | 73 |
}
|
| 72 | 74 |
|