Last active
June 9, 2016 15:37
-
-
Save dolohow/10d86debd4389007621a to your computer and use it in GitHub Desktop.
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" | |
"time" | |
) | |
func main() { | |
c := make(chan int) | |
fmt.Println("Program started") | |
go func() { | |
fmt.Println("Enter goroutine") | |
time.Sleep(time.Duration(3) * time.Second) | |
c <- 1 | |
fmt.Println("Exit goroutine") | |
}() | |
fmt.Println("Main thread... waiting for result") | |
for { | |
select { | |
case <-c: | |
fmt.Println("Got result, exiting loop") | |
os.Exit(0) | |
default: | |
time.Sleep(time.Duration(500) * time.Millisecond) | |
fmt.Print(".") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment