If you want to transfer data from one routine to another, you can do it like
package main import "fmt" func routine(output chan int) { for i := 0; i < 1000; i++ { output <- i } close(output) } func main() { ch := make(chan int) go routine(ch) for i := range ch { fmt.Printf("%d ", i) } }
But this is not quite what you asked for, you wanted to get a routine status every second. For this channel is not a good solution. A variable shared between two routines will solve the problem. One routine updates it, another procedure reads it every second.
Grzegorz Żur
source share