Started migration to sub-packages
This commit is contained in:
parent
51a6001bb9
commit
b461343171
6 changed files with 69 additions and 29 deletions
36
internal/events/event.go
Normal file
36
internal/events/event.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
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
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue