blob: fbc39caac21e651f8d14c1ef6c411fdcc679bb43 [file] [log] [blame]
Shenghou Ma5b7562d2012-09-03 03:49:03 +08001// compile
2
Francisco Souza56598262012-03-14 13:03:11 +11003// Copyright 2012 The Go Authors. All rights reserved.
4// Use of this source code is governed by a BSD-style
5// license that can be found in the LICENSE file.
6package timeout
7
8import (
9 "time"
10)
11
12func Timeout() {
13 ch := make(chan bool, 1)
14 timeout := make(chan bool, 1)
15 go func() {
Rob Pikea99e9c52012-03-23 07:51:16 +110016 time.Sleep(1 * time.Second)
Francisco Souza56598262012-03-14 13:03:11 +110017 timeout <- true
18 }()
19
20 // STOP OMIT
21
22 select {
23 case <-ch:
24 // a read from ch has occurred
25 case <-timeout:
26 // the read from ch has timed out
27 }
28
29 // STOP OMIT
30}