Skip to content

Instantly share code, notes, and snippets.

@ijt
Created May 1, 2011 20:37
Show Gist options
  • Save ijt/950849 to your computer and use it in GitHub Desktop.
Save ijt/950849 to your computer and use it in GitHub Desktop.
How to call Printf in a goroutine without hanging
package main
import (
"fmt"
"os"
)
func PrintInts() {
for i := 0; ; i++ {
fmt.Printf("%d\r", i)
}
}
func main() {
go PrintInts()
for {
// With the next line, the program just hangs.
os.Stdout.Sync()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment