Skip to content

StephanoGeorge/event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event in Go

Implementation of Python threading.Event in Go, add channel support

Features

  • Can be Set() and Clear() multiple times
  • Add Channel support, can receive events from then channel every time Clear() is called

Example

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()
}()

About

Implementation of Python threading.Event in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages