1 // Copyright 2012 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package timeout 6 7 import ( 8 "time" 9 ) 10 11 func Timeout() { 12 ch := make(chan bool, 1) 13 timeout := make(chan bool, 1) 14 go func() { 15 time.Sleep(1 * time.Second) 16 timeout <- true 17 }() 18 19 // STOP OMIT 20 21 select { 22 case <-ch: 23 // a read from ch has occurred 24 case <-timeout: 25 // the read from ch has timed out 26 } 27 28 // STOP OMIT 29 } 30