|
@ -38,11 +38,9 @@ type Reactor struct { |
|
|
logger log.Logger |
|
|
logger log.Logger |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
var bufferSize int = 10 |
|
|
|
|
|
|
|
|
|
|
|
func NewReactor() *Reactor { |
|
|
|
|
|
|
|
|
func NewReactor(bufferSize int) *Reactor { |
|
|
return &Reactor{ |
|
|
return &Reactor{ |
|
|
events: make(chan Event, bufferSize*2), |
|
|
|
|
|
|
|
|
events: make(chan Event, bufferSize), |
|
|
stopDemux: make(chan struct{}), |
|
|
stopDemux: make(chan struct{}), |
|
|
scheduler: newRoutine("scheduler", schedulerHandle, bufferSize), |
|
|
scheduler: newRoutine("scheduler", schedulerHandle, bufferSize), |
|
|
processor: newRoutine("processor", processorHandle, 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?
|
|
|
// of events that each routine can produce and consume?
|
|
|
func (r *Reactor) demux() { |
|
|
func (r *Reactor) demux() { |
|
|
for { |
|
|
for { |
|
@ -82,7 +80,7 @@ func (r *Reactor) demux() { |
|
|
// XXX: check for backpressure
|
|
|
// XXX: check for backpressure
|
|
|
r.scheduler.send(event) |
|
|
r.scheduler.send(event) |
|
|
r.processor.send(event) |
|
|
r.processor.send(event) |
|
|
case _ = <-r.stopDemux: |
|
|
|
|
|
|
|
|
case <-r.stopDemux: |
|
|
r.logger.Info("demuxing stopped") |
|
|
r.logger.Info("demuxing stopped") |
|
|
return |
|
|
return |
|
|
case event := <-r.scheduler.next(): |
|
|
case event := <-r.scheduler.next(): |
|
@ -112,6 +110,7 @@ func (r *Reactor) Stop() { |
|
|
|
|
|
|
|
|
func (r *Reactor) Receive(event Event) { |
|
|
func (r *Reactor) Receive(event Event) { |
|
|
// XXX: decode and serialize write events
|
|
|
// XXX: decode and serialize write events
|
|
|
|
|
|
// TODO: backpressure
|
|
|
r.events <- event |
|
|
r.events <- event |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|