Event is a simple locking primitives which allows for sending notifications across goroutines when an event has occurred.
package main
import (
"fmt"
"sync"
"time"
"github.com/pkg/errors"
"github.com/trivigy/event"
)
func main() {
mutex := sync.Mutex{}
results := make([]error, 0)
start := sync.WaitGroup{}
finish := sync.WaitGroup{}
N := 5
start.Add(N)
finish.Add(N)
for i := 0; i < N; i++ {
go func() {
start.Done()
value := event.Wait(nil)
mutex.Lock()
results = append(results, value)
mutex.Unlock()
finish.Done()
}()
}
start.Wait()
time.Sleep(100 * time.Millisecond)
event.Set()
finish.Wait()
fmt.Printf("%+v\n", results)
}