Created
May 1, 2011 20:37
-
-
Save ijt/950849 to your computer and use it in GitHub Desktop.
How to call Printf in a goroutine without hanging
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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