summaryrefslogtreecommitdiff
path: root/manager
diff options
context:
space:
mode:
authorSilvan Jegen <s.jegen@gmail.com>2017-02-15 12:55:58 +0100
committerSilvan Jegen <s.jegen@gmail.com>2017-02-15 12:56:21 +0100
commit5147048d4a67c59f799203e1cc5f79b183208cab (patch)
treeb3f8ac1a12b6d164809abc00c1a8dc05ed8ad56c /manager
parentaab7d33eba775fc497e651d8bfb1537980b5d91e (diff)
Put the Manager in its own package
Diffstat (limited to 'manager')
-rw-r--r--manager/manager.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/manager/manager.go b/manager/manager.go
new file mode 100644
index 0000000..5bbd49f
--- /dev/null
+++ b/manager/manager.go
@@ -0,0 +1,46 @@
+package manager
+
+import (
+ "fmt"
+ "sync"
+
+ "github.com/Shugyousha/stasher/filter"
+ "github.com/Shugyousha/stasher/input"
+ "github.com/Shugyousha/stasher/output"
+ "github.com/Shugyousha/stasher/work"
+)
+
+type Manager struct {
+ Input input.Input
+ Filter filter.Filter
+ Output output.Output
+}
+
+func (m *Manager) Run() {
+ var wg sync.WaitGroup
+
+ ic := m.Input.Start()
+ for w := range ic {
+ if w.Err != nil {
+ fmt.Printf("Got an error when getting Work input: %q\n", w.Err)
+ continue
+ }
+ 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 filtering Work: %q\n", err)
+ }
+ err = m.Output.Output(nw)
+ if err != nil {
+ fmt.Printf("Got an error when outputting Work: %q\n", err)
+ }
+
+ wg.Done()
+ }(w)
+ }
+
+ wg.Wait()
+}