Commit 9dba7335 authored by Elbert Fliek's avatar Elbert Fliek Committed by Ian Lance Taylor

time: add an example to the NewTicker function

Change-Id: Idad9cdee36679373ee223ff2bd4c021ea0afcce1
Reviewed-on: https://go-review.googlesource.com/61710Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent b65cffdc
......@@ -127,6 +127,25 @@ func ExampleDate() {
// Output: Go launched at 2009-11-10 15:00:00 -0800 PST
}
func ExampleNewTicker() {
ticker := time.NewTicker(time.Second)
defer ticker.Stop()
done := make(chan bool)
go func() {
time.Sleep(10 * time.Second)
done <- true
}()
for {
select {
case <-done:
fmt.Println("Done!")
return
case t := <-ticker.C:
fmt.Println("Current time: ", t)
}
}
}
func ExampleTime_Format() {
// Parse a time value from a string in the standard Unix format.
t, err := time.Parse(time.UnixDate, "Sat Mar 7 11:06:39 PST 2015")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment