Skip to content

Instantly share code, notes, and snippets.

@dolohow
Last active June 9, 2016 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dolohow/10d86debd4389007621a to your computer and use it in GitHub Desktop.
Save dolohow/10d86debd4389007621a to your computer and use it in GitHub Desktop.
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