awaiter
WaitGroup like module to await goroutines
Description
Awaiter is similar to a WaitGroup but simplifies the resource handling.
change this:
wg := new(sync.WaitGroup)
counter := 0
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Second * 1)
counter += 1
}()
wg.Add(1)
go func() {
defer wg.Done()
time.Sleep(time.Second * 1)
counter += 1
}()
wg.Wait()
fmt.Printf("counter: %d", counter)
// Output: counter: 2
to this:
awaiter := awaiter.New()
counter := 0
awaiter.Go(func() {
time.Sleep(time.Second * 1)
counter += 1
})
awaiter.Go(func() {
time.Sleep(time.Second * 1)
counter += 1
})
awaiter.AwaitSync()
fmt.Printf("counter: %d", counter)
// Output: counter: 2
See more examples here and the docs here
Installation
go get github.com/v-braun/awaiter
Authors
Contributing
Make sure to read these guides before getting started:
License
awaiter is available under the MIT License. See LICENSE for details.