Browse Source

cleanup events

pull/3907/head
Sean Braithwaite 5 years ago
parent
commit
5b880fbcff
5 changed files with 12 additions and 41 deletions
  1. +3
    -0
      blockchain/v2/demuxer.go
  2. +7
    -9
      blockchain/v2/reactor.go
  3. +1
    -1
      blockchain/v2/reactor_test.go
  4. +1
    -0
      blockchain/v2/routine_test.go
  5. +0
    -31
      blockchain/v2/types.go

+ 3
- 0
blockchain/v2/demuxer.go View File

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


+ 7
- 9
blockchain/v2/reactor.go 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{})


+ 1
- 1
blockchain/v2/reactor_test.go View File

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


+ 1
- 0
blockchain/v2/routine_test.go View File

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


+ 0
- 31
blockchain/v2/types.go 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{}

Loading…
Cancel
Save