Permalink
Browse files

Change API: PipelineRunner -> Net

  • Loading branch information...
samuell committed Aug 25, 2016
1 parent 569d809 commit 66ad7931c8b96ccc07075e9b569c3c0012f4ea83
Showing with 54 additions and 54 deletions.
  1. +50 −0 network.go
  2. +4 −4 pipeline_test.go → network_test.go
  3. +0 −50 pipeline.go
View
@@ -0,0 +1,50 @@
package flowbase
import (
"fmt"
"os"
"reflect"
)
type Net struct {
processes []Process
}
func NewNet() *Net {
return &Net{}
}
func (pl *Net) AddProcess(proc Process) {
pl.processes = append(pl.processes, proc)
}
func (pl *Net) AddProcesses(procs ...Process) {
for _, proc := range procs {
pl.AddProcess(proc)
}
}
func (pl *Net) PrintProcesses() {
for i, proc := range pl.processes {
fmt.Printf("Process %d: %v\n", i, reflect.TypeOf(proc))
}
}
func (pl *Net) Run() {
if !LogExists {
InitLogAudit()
}
if len(pl.processes) == 0 {
Error.Println("Net: The Net is empty. Did you forget to add the processes to it?")
os.Exit(1)
}
for i, proc := range pl.processes {
if i < len(pl.processes)-1 {
Debug.Printf("Net: Starting process %d of type %v: in new go-routine...\n", i, reflect.TypeOf(proc))
go proc.Run()
} else {
Debug.Printf("Net: Starting process %d of type %v: in main go-routine...\n", i, reflect.TypeOf(proc))
proc.Run()
}
}
}
@@ -10,7 +10,7 @@ func TestAddProcesses(t *t.T) {
proc1 := NewBogusProcess()
proc2 := NewBogusProcess()
pipeline := NewPipelineRunner()
pipeline := NewNet()
pipeline.AddProcesses(proc1, proc2)
assert.EqualValues(t, len(pipeline.processes), 2)
@@ -19,11 +19,11 @@ func TestAddProcesses(t *t.T) {
assert.IsType(t, &BogusProcess{}, pipeline.processes[1], "Process 2 was not of the right type!")
}
func TestRunProcessesInPipelineRunner(t *t.T) {
func TestRunProcessesInNet(t *t.T) {
proc1 := NewBogusProcess()
proc2 := NewBogusProcess()
pipeline := NewPipelineRunner()
pipeline := NewNet()
pipeline.AddProcesses(proc1, proc2)
pipeline.Run()
@@ -39,7 +39,7 @@ func ExamplePrintProcesses() {
proc1 := NewBogusProcess()
proc2 := NewBogusProcess()
pipeline := NewPipelineRunner()
pipeline := NewNet()
pipeline.AddProcesses(proc1, proc2)
pipeline.Run()
View

This file was deleted.

Oops, something went wrong.

0 comments on commit 66ad793

Please sign in to comment.