What you did is decouple production from consumption. You can speed up the 
production go routine if the rate is irregular. But if, on average, consumption 
is too slow, the list will grow until out of memory. 

If you want to speed up consumption, you may group the strings in one big 
string and print once. This will reduce the rate of system calls to print each 
string individually.

Something like this (warning: raw untested code)


buf := make([]byte, 0, 1024)
ticker := time.NewTicker(1*time.Second)
for {
    select {
    case ticker.C:
        if len(buf) > 0 {
            fmt.Print(string(buf))
            buf := buf[:0]
        }
    case m := <-buffChan:
        buf = append(buf, m...)
        buf = append(buf, '\n')
    }
}


Adjust the ticker period time and initial buffer size to what matches your 
need. 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to