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()
gofunc() {
e.Wait()
}()
gofunc() {
e.Clear()
}()
gofunc() {
e.Set()
}()With channel
e:=event.Event(true)
gofunc() {
for {
select {
case<-e.WaitChan:
fmt.Println("Cleared")
case<-time.After(time.Minute):
fmt.Println("Timed out")
}
}
}()
gofunc() {
e.Wait()
}()
gofunc() {
e.Clear()
}()
gofunc() {
e.Set()
}()
gofunc() {
e.Close()
}()