diff options
| author | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 23:40:10 +0100 |
|---|---|---|
| committer | Paul Buetow (europa) <paul@buetow.org> | 2015-05-24 23:40:10 +0100 |
| commit | ee387a8539c60e5c9c1d6894fce07e74c9414665 (patch) | |
| tree | 0a434ca74bd697daf01b78e0416a8e803b2c07e6 | |
| parent | 50c041108dc321cf37f191dfb697cee0ade426d2 (diff) | |
gather and receiver works
| -rw-r--r-- | main/main.go | 42 | ||||
| -rw-r--r-- | process/process.go | 4 |
2 files changed, 20 insertions, 26 deletions
diff --git a/main/main.go b/main/main.go index d1f031c..72497df 100644 --- a/main/main.go +++ b/main/main.go @@ -3,45 +3,43 @@ package main import ( "fmt" "github.com/buetow/gstat/process" + "time" ) -const ( - STOP = 0 - GETPIDS = 1 -) - -func gstatGather(action <-chan int, res chan<- process.Process) { +func gather(timer <-chan bool, processes chan<- process.Process) { for { - switch <-action { - case STOP: + switch <-timer { + case false: { break } - case GETPIDS: + case true: { - process.Gather(res) + process.Gather(processes) } } - close(res) + } + close(processes) +} + +func receive(processes <-chan process.Process) { + for process := range processes { + fmt.Println(process) } } func main() { - action := make(chan int) + timer := make(chan bool) res := make(chan process.Process) - go gstatGather(action, res) + go gather(timer, res) + go receive(res) - action <- GETPIDS - for { - process, more := <-res - if more { - process.Print() - } else { - break - } + for counter := 0; counter < 3; counter++ { + timer <- true + time.Sleep(time.Second) } - action <- STOP + timer <- false fmt.Println("Good bye") } diff --git a/process/process.go b/process/process.go index c0e25e2..6f4ec11 100644 --- a/process/process.go +++ b/process/process.go @@ -22,10 +22,6 @@ func (self *Process) String() string { return str } -func (self *Process) Print() { - fmt.Println(self) -} - func Gather(res chan<- Process) { re, _ := regexp.Compile("^[0-9]+$") |
