1// Copyright 2021 The Go Authors. All rights reserved.  Use of this
2// source code is governed by a BSD-style license that can be found in
3// the LICENSE file.
4
5package a
6
7// A StoppableWaitGroup waits for a collection of goroutines to finish.
8type StoppableWaitGroup struct {
9	// i is the internal counter which can store tolerate negative values
10	// as opposed the golang's library WaitGroup.
11	i *int64
12}
13
14// NewStoppableWaitGroup returns a new StoppableWaitGroup. When the 'Stop' is
15// executed, following 'Add()' calls won't have any effect.
16func NewStoppableWaitGroup() *StoppableWaitGroup {
17	return &StoppableWaitGroup{
18		i: func() *int64 { i := int64(0); return &i }(),
19	}
20}
21