Skip to content

Commit

Permalink
Add buffered output, possibly faster
Browse files Browse the repository at this point in the history
  • Loading branch information
kalmanb committed May 30, 2017
1 parent c1b2d78 commit d9b5021
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion go/main.go
@@ -1,6 +1,7 @@
package main

import (
"bufio"
"flag"
"os"
)
Expand All @@ -10,12 +11,17 @@ func main() {
var interval = flag.Int("interval", 10, "Refresh interveal in seconds, defaults to 10 secounds")
flag.Parse()

out := bufio.NewWriter(os.Stdout)
writer := make(chan []byte)
go func() {
for {
b := <-writer
b = append(b, byte('\n'))
_, err := os.Stdout.Write(b)
_, err := out.Write(b)
if err != nil {
panic("Could not write to stdout")
}
err = out.Flush()
if err != nil {
panic("Could not write to stdout")
}
Expand Down

0 comments on commit d9b5021

Please sign in to comment.