From 26412f3077698dabcdbdf6a6e40276c56a6f74b5 Mon Sep 17 00:00:00 2001 From: Silvan Jegen Date: Fri, 9 Dec 2016 21:12:18 +0100 Subject: Reorganize files --- types.go | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 types.go (limited to 'types.go') diff --git a/types.go b/types.go new file mode 100644 index 0000000..abd2658 --- /dev/null +++ b/types.go @@ -0,0 +1,48 @@ +package main + +import ( + "fmt" + "sync" + + "github.com/Shugyousha/stasher/work" +) + +type Input interface { + Start() chan *work.Work +} + +type Filter interface { + Filter(*work.Work) *work.Work +} + +type Output interface { + Output(*work.Work) +} + +type Manager struct { + Input Input + Filter Filter + Output Output +} + +func (m *Manager) Run() { + var wg sync.WaitGroup + + ic := m.Input.Start() + for w := range ic { + wg.Add(1) + + go func(w *work.Work) { + nw := m.Filter.Filter(w) + err := nw.Error() + if err != nil { + fmt.Printf("Got an error when processing Work: %q\n", err) + } + m.Output.Output(nw) + + wg.Done() + }(w) + } + + wg.Wait() +} -- cgit v1.2.1-18-gbd029