wireguard-go/internal/events/event.go

37 lines
495 B
Go
Raw Normal View History

2018-02-09 18:56:00 +01:00
package events
import (
"sync"
)
type Event interface {
Contains(int) bool
Processed()
WaitForProcessed()
}
type EventStruct struct {
code int
lock sync.Mutex
}
func (event EventStruct) Contains(code int) bool {
return event.code&code != 0
}
func (event *EventStruct) WaitForProcessed() {
event.lock.Lock()
}
func (event *EventStruct) Processed() {
event.lock.Unlock()
}
func NewEvent(code int) Event {
event := &EventStruct{
code: code,
}
event.lock.Lock()
return event
}