init shutdownNotifier before ranging options
Vladimir Bauer
3 years ago
| 72 | 72 | // method has been called. |
| 73 | 73 | func NewWithContext(ctx context.Context, options ...ContainerOption) *Progress { |
| 74 | 74 | s := &pState{ |
| 75 | rr: prr, | |
| 76 | bHeap: priorityQueue{}, | |
| 77 | rows: make([]io.Reader, 0, 64), | |
| 78 | pool: make([]*Bar, 0, 64), | |
| 79 | manualRefresh: make(chan interface{}), | |
| 80 | queueBars: make(map[*Bar]*Bar), | |
| 81 | popPriority: math.MinInt32, | |
| 82 | output: os.Stdout, | |
| 83 | debugOut: io.Discard, | |
| 75 | rr: prr, | |
| 76 | bHeap: priorityQueue{}, | |
| 77 | rows: make([]io.Reader, 0, 64), | |
| 78 | pool: make([]*Bar, 0, 64), | |
| 79 | manualRefresh: make(chan interface{}), | |
| 80 | shutdownNotifier: make(chan struct{}), | |
| 81 | queueBars: make(map[*Bar]*Bar), | |
| 82 | popPriority: math.MinInt32, | |
| 83 | output: os.Stdout, | |
| 84 | debugOut: io.Discard, | |
| 84 | 85 | } |
| 85 | 86 | |
| 86 | 87 | for _, opt := range options { |
| 87 | 88 | if opt != nil { |
| 88 | 89 | opt(s) |
| 89 | 90 | } |
| 90 | } | |
| 91 | ||
| 92 | if s.shutdownNotifier == nil { | |
| 93 | s.shutdownNotifier = make(chan struct{}) | |
| 94 | 91 | } |
| 95 | 92 | |
| 96 | 93 | ctx, cancel := context.WithCancel(ctx) |