From ecde4df0f41b5c4bddf1416a4aa60f196f73682c Mon Sep 17 00:00:00 2001 From: Sean Braithwaite Date: Wed, 31 Jul 2019 08:10:47 +0200 Subject: [PATCH] add some notes + intentions --- blockchain/v2/reactor.go | 25 +++++++++++++++++++++++++ blockchain/v2/routines.go | 28 +++------------------------- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/blockchain/v2/reactor.go b/blockchain/v2/reactor.go index 1226139c..feab4e53 100644 --- a/blockchain/v2/reactor.go +++ b/blockchain/v2/reactor.go @@ -5,6 +5,31 @@ import ( "time" ) +func schedulerHandle(event Event) Events { + switch event.(type) { + case timeCheck: + fmt.Println("scheduler handle timeCheck") + case testEvent: + fmt.Println("scheduler handle testEvent") + return Events{scTestEvent{}} + } + return Events{} +} + +func processorHandle(event Event) Events { + switch event.(type) { + case timeCheck: + fmt.Println("processor handle timeCheck") + case testEvent: + fmt.Println("processor handle testEvent") + case scTestEvent: + fmt.Println("processor handle scTestEvent") + // should i stop myself? + return Events{pcFinished{}} + } + return Events{} +} + // reactor type Reactor struct { events chan Event diff --git a/blockchain/v2/routines.go b/blockchain/v2/routines.go index 87c04671..09f18a5e 100644 --- a/blockchain/v2/routines.go +++ b/blockchain/v2/routines.go @@ -34,6 +34,8 @@ func newRoutine(name string, output chan Event, handleFunc handleFunc) *Routine } } +// TODO: refactor the handle to return an second variable, error which can signal +//to the run looop when the handler is done func (rt *Routine) run() { fmt.Printf("%s: run\n", rt.name) for { @@ -45,6 +47,7 @@ func (rt *Routine) run() { return } oEvents := rt.handle(iEvent) + // XXX: this should check for error and exit if error fmt.Printf("%s handled %d events\n", rt.name, len(oEvents)) for _, event := range oEvents { // check for finished @@ -108,28 +111,3 @@ func (rt *Routine) stop() { func (rt *Routine) wait() { <-rt.finished } - -func schedulerHandle(event Event) Events { - switch event.(type) { - case timeCheck: - fmt.Println("scheduler handle timeCheck") - case testEvent: - fmt.Println("scheduler handle testEvent") - return Events{scTestEvent{}} - } - return Events{} -} - -func processorHandle(event Event) Events { - switch event.(type) { - case timeCheck: - fmt.Println("processor handle timeCheck") - case testEvent: - fmt.Println("processor handle testEvent") - case scTestEvent: - fmt.Println("processor handle scTestEvent") - // should i stop myself? - return Events{pcFinished{}} - } - return Events{} -}