<commit_before>// Package throttled implements various helpers to manage the lifecycle of goroutines.
package throttled

// WaitGroup limits the number of concurrent goroutines.
type WaitGroup struct {
	throttle    int
	completed   chan bool
	outstanding int
}

// NewWaitGroup instantiates a new WaitGroup with the given throttle.
func NewWaitGroup(throttle int) *WaitGroup {
	return &WaitGroup{
		outstanding: 0,
		throttle:    throttle,
		completed:   make(chan bool, throttle),
	}
}

// Add will block until the number of goroutines being throttled
// has fallen below the throttle
func (w *WaitGroup) Add() {
	if w.outstanding+1 > w.throttle {
		select {
		case <-w.completed:
			w.outstanding--
			return
		}
	}
	w.outstanding++
}

// Done signal that a goroutine has completed
func (w *WaitGroup) Done() {
	w.completed <- true
}

// Wait until all of the throttled goroutines have signaled they are done
func (w *WaitGroup) Wait() {
	if w.outstanding == 0 {
		return
	}<commit_msg>Add bugfix - needed to increment outstanding at point of add<commit_after>// Package throttled implements various helpers to manage the lifecycle of goroutines.
package throttled

// WaitGroup limits the number of concurrent goroutines that can execute at once.
type WaitGroup struct {
	throttle    int
	completed   chan bool
	outstanding int
}

// NewWaitGroup instantiates a new WaitGroup with the given throttle.
func NewWaitGroup(throttle int) *WaitGroup {
	return &WaitGroup{
		outstanding: 0,
		throttle:    throttle,
		completed:   make(chan bool, throttle),
	}
}

// Add will block until the number of goroutines being throttled
// has fallen below the throttle.
func (w *WaitGroup) Add() {
	w.outstanding++
	if w.outstanding > w.throttle {
		select {
		case <-w.completed:
			w.outstanding--
			return
		}
	}
}

// Done signal that a goroutine has completed.
func (w *WaitGroup) Done() {
	w.completed <- true
}

// Wait until all of the throttled goroutines have signaled they are done.
func (w *WaitGroup) Wait() {
	if w.outstanding == 0 {
		return
	}
{'fraction_non_alphanumeric': 0.084431429965837, 'fraction_numerical': 0.002440214738897023, 'mean_word_length': 3.596412556053812, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2586651', 'n_tokens_mistral': 712, 'n_tokens_neox': 632, 'n_words': 244}