summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/braintree/manners/test_helpers/wait_group.go
blob: 1df590db70fbd9b2ee66af3333e73e24e8d42b0c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package test_helpers

import "sync"

type WaitGroup struct {
	sync.Mutex
	Count      int
	WaitCalled chan int
}

func NewWaitGroup() *WaitGroup {
	return &WaitGroup{
		WaitCalled: make(chan int, 1),
	}
}

func (wg *WaitGroup) Add(delta int) {
	wg.Lock()
	wg.Count++
	wg.Unlock()
}

func (wg *WaitGroup) Done() {
	wg.Lock()
	wg.Count--
	wg.Unlock()
}

func (wg *WaitGroup) Wait() {
	wg.Lock()
	wg.WaitCalled <- wg.Count
	wg.Unlock()
}