Browse Source

tidying

pull/3878/head
Sean Braithwaite 5 years ago
parent
commit
d3d034e572
2 changed files with 10 additions and 7 deletions
  1. +5
    -6
      blockchain/v2/reactor.go
  2. +5
    -1
      blockchain/v2/reactor_test.go

+ 5
- 6
blockchain/v2/reactor.go View File

@ -38,11 +38,9 @@ type Reactor struct {
logger log.Logger
}
var bufferSize int = 10
func NewReactor() *Reactor {
func NewReactor(bufferSize int) *Reactor {
return &Reactor{
events: make(chan Event, bufferSize*2),
events: make(chan Event, bufferSize),
stopDemux: make(chan struct{}),
scheduler: newRoutine("scheduler", schedulerHandle, bufferSize),
processor: newRoutine("processor", processorHandle, bufferSize),
@ -73,7 +71,7 @@ func (r *Reactor) Start() {
}()
}
// Would it be possible here to provide some kind of type safety for the types
// XXX: Would it be possible here to provide some kind of type safety for the types
// of events that each routine can produce and consume?
func (r *Reactor) demux() {
for {
@ -82,7 +80,7 @@ func (r *Reactor) demux() {
// XXX: check for backpressure
r.scheduler.send(event)
r.processor.send(event)
case _ = <-r.stopDemux:
case <-r.stopDemux:
r.logger.Info("demuxing stopped")
return
case event := <-r.scheduler.next():
@ -112,6 +110,7 @@ func (r *Reactor) Stop() {
func (r *Reactor) Receive(event Event) {
// XXX: decode and serialize write events
// TODO: backpressure
r.events <- event
}


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

@ -5,7 +5,11 @@ import (
)
func TestReactor(t *testing.T) {
reactor := NewReactor()
var (
bufferSize = 10
reactor = NewReactor(bufferSize)
)
reactor.Start()
script := []Event{
// TODO


Loading…
Cancel
Save