Implementation of Python threading.Event in Go, add channel support
- Can be
Set()
andClear()
multiple times - Add Channel support, can receive events from then channel every time
Clear()
is called
import (
"github.com/StephanoGeorge/event"
)
e := event.Event()
go func() {
e.Wait()
}()
go func() {
e.Clear()
}()
go func() {
e.Set()
}()
With channel
e := event.Event(true)
go func() {
for {
select {
case <-e.WaitChan:
fmt.Println("Cleared")
case <-time.After(time.Minute):
fmt.Println("Timed out")
}
}
}()
go func() {
e.Wait()
}()
go func() {
e.Clear()
}()
go func() {
e.Set()
}()
go func() {
e.Close()
}()