Skip to content
StephanoGeorgePublic

About

Implementation of Python threading.Event in Go

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

 

History

12 Commits

Folders and files

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

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages