Files
build-web-application-with-…/de/code/src/apps/ch.2.7/timeout/main.go
2015-08-06 20:35:55 +02:00

28 lines
403 B
Go

// Example code for Chapter 2.7 from "Build Web Application with Golang"
// Purpose: Shows how to create and use a timeout
package main
import (
"fmt"
"time"
)
func main() {
c := make(chan int)
o := make(chan bool)
go func() {
for {
select {
case v := <-c:
fmt.Println(v)
case <-time.After(5 * time.Second):
fmt.Println("timeout")
o <- true
break
}
}
}()
<-o
}