https://github.com/trivigy/event
Implemention of python's threading.Event using golang primitives
https://github.com/trivigy/event
concurrency events locking notifications
Last synced: about 2 months ago
JSON representation
Implemention of python's threading.Event using golang primitives
- Host: GitHub
- URL: https://github.com/trivigy/event
- Owner: trivigy
- License: mit
- Created: 2019-05-25T17:25:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-07-13T07:14:13.000Z (almost 7 years ago)
- Last Synced: 2025-07-05T20:52:12.500Z (10 months ago)
- Topics: concurrency, events, locking, notifications
- Language: Go
- Homepage:
- Size: 15.6 KB
- Stars: 7
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Event
[](https://circleci.com/gh/trivigy/workflows/event)
[](LICENSE.md)
[](http://godoc.org/github.com/trivigy/event)
[](https://github.com/trivigy/event/releases/latest)
## Introduction
Event is a simple locking primitives which allows for sending notifications
across goroutines when an event has occurred.
## Example
```go
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)
}
```