Skip to content
master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Event

CircleCI branch License GitHub tag (latest SemVer)

Introduction

Event is a simple locking primitives which allows for sending notifications across goroutines when an event has occurred.

Example

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

About

Implemention of python's threading.Event using golang primitives

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages