cleanup events

This commit is contained in:
Sean Braithwaite 2019-08-08 15:53:02 +02:00
parent c081b60ef6
commit 5b880fbcff
5 changed files with 12 additions and 41 deletions

View File

@ -5,6 +5,9 @@ import (
"sync/atomic"
)
type scFull struct{}
type pcFull struct{}
type demuxer struct {
input chan Event
scheduler *Routine

View File

@ -5,13 +5,16 @@ import (
"time"
)
type timeCheck struct {
time time.Time
}
func schedulerHandle(event Event) (Events, error) {
switch event.(type) {
case timeCheck:
fmt.Println("scheduler handle timeCheck")
case testEvent:
case Event:
fmt.Println("scheduler handle testEvent")
return Events{scTestEvent{}}, nil
}
return Events{}, nil
}
@ -20,11 +23,8 @@ func processorHandle(event Event) (Events, error) {
switch event.(type) {
case timeCheck:
fmt.Println("processor handle timeCheck")
case testEvent:
fmt.Println("processor handle testEvent")
case scTestEvent:
fmt.Println("processor handle scTestEvent")
return Events{}, fmt.Errorf("processor done")
case Event:
fmt.Println("processor handle event")
}
return Events{}, nil
}
@ -40,10 +40,8 @@ type Reactor struct {
// TODO: setLogger should set loggers of the routines
func (r *Reactor) Start() {
// what is the best way to get the events out of the routine
r.scheduler = newRoutine("scheduler", schedulerHandle)
r.processor = newRoutine("processor", processorHandle)
// so actually the demuxer only needs to read from events
r.demuxer = newDemuxer(r.scheduler, r.processor)
r.tickerStopped = make(chan struct{})

View File

@ -7,7 +7,7 @@ func TestReactor(t *testing.T) {
reactor := Reactor{}
reactor.Start()
script := Events{
testEvent{},
struct{}{},
}
for _, event := range script {

View File

@ -11,6 +11,7 @@ import (
type eventA struct{}
type eventB struct{}
type errEvent struct{}
var done = fmt.Errorf("done")

View File

@ -1,35 +1,4 @@
package v2
import "time"
type Event interface{}
type Events []Event
type testEvent struct {
msg string
time time.Time
}
type testEventTwo struct {
msg string
}
type stopEvent struct{}
type timeCheck struct {
time time.Time
}
type errEvent struct{}
type scTestEvent struct{}
type pcFinished struct{}
type routineFinished struct{}
func (rf *routineFinished) Error() string {
return "routine finished"
}
type scFull struct{}
type pcFull struct{}