Skip to content

Latest commit

 

History

History
32 lines (24 loc) · 538 Bytes

README.md

File metadata and controls

32 lines (24 loc) · 538 Bytes

goro

Go library that provides sync.Once capability that can be reset.

Usage

Documentation is available via GoDoc.

func ExampleGoro() {
	var once goro.Once
	var counter int
	var wg sync.WaitGroup

	for i := 0; i < 100; i++ {
		wg.Add(1)
		go func(j int) {
			defer wg.Done()

			if j == 25 {
				once.Reset()
			}

			once.Do(func() { counter++ })
		}(i)
	}

	fmt.Println("counter:", counter)
	// Output: counter: 2
}