diff --git a/bar.go b/bar.go index 8a73d23..f08d111 100644 --- a/bar.go +++ b/bar.go @@ -58,8 +58,8 @@ extender extenderFunc debugOut io.Writer - // afterBar is a key for (*pState).queueBars - afterBar *Bar + afterBar *Bar // key for (*pState).queueBars + sync bool } type frame struct { @@ -300,6 +300,9 @@ func (b *Bar) serve(ctx context.Context, bs *bState) { defer b.container.bwg.Done() + if bs.afterBar != nil && bs.sync { + <-bs.afterBar.done + } for { select { case op := <-b.operateState: diff --git a/bar_option.go b/bar_option.go index b62dba7..8599f0a 100644 --- a/bar_option.go +++ b/bar_option.go @@ -60,14 +60,16 @@ } // BarQueueAfter puts this (being constructed) bar into the queue. -// Queued bar will run after argument bar completes, replacing its -// place. While bar is queued all of its methods are blocked. -func BarQueueAfter(bar *Bar) BarOption { +// When argument bar completes or aborts queued bar replaces its place. +// If sync is true queued bar is suspended until argument bar completes +// or aborts. +func BarQueueAfter(bar *Bar, sync bool) BarOption { if bar == nil { return nil } return func(s *bState) { s.afterBar = bar + s.sync = sync } }