aboutsummaryrefslogtreecommitdiff
path: root/src/time/example_test.go
diff options
context:
space:
mode:
authorElbert Fliek <efliek@gmail.com>2017-09-05 20:21:41 +0200
committerIan Lance Taylor <iant@golang.org>2017-09-09 06:32:44 +0000
commit9dba7335c041677c18eaa245a106f9865b651d84 (patch)
tree0443f9a25ee512d8b5ca0406dab53cd213680a27 /src/time/example_test.go
parentb65cffdcd82212f6072555637fe7529aa88bb225 (diff)
downloadgo-9dba7335c041677c18eaa245a106f9865b651d84.tar.gz
go-9dba7335c041677c18eaa245a106f9865b651d84.zip
time: add an example to the NewTicker function
Change-Id: Idad9cdee36679373ee223ff2bd4c021ea0afcce1 Reviewed-on: https://go-review.googlesource.com/61710 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/time/example_test.go')
-rw-r--r--src/time/example_test.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 5aca97f08f..8d019a0f21 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -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")