chandra agung rizky has uploaded this change for review.
time: add example for NewTimer function
Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
---
M src/time/example_test.go
1 file changed, 21 insertions(+), 0 deletions(-)
diff --git a/src/time/example_test.go b/src/time/example_test.go
index 0afb18a..6c6cd89 100644
--- a/src/time/example_test.go
+++ b/src/time/example_test.go
@@ -662,3 +662,24 @@
fmt.Println("The time is:", t.Format(time.RFC822))
// Output: The time is: 10 Nov 09 23:00 UTC-8
}
+
+func ExampleNewTimer() {
+
+ timer := time.NewTimer(2 * time.Second)
+ done := make(chan bool)
+
+ go func() {
+ <-timer.C
+ done <- true
+ }()
+
+ for {
+ select {
+ case <-done:
+ fmt.Println("timer expired")
+ break
+ default:
+ fmt.Println("timer in progress")
+ }
+ }
+}
To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: chandra agung rizky.
1 comment:
File src/time/example_test.go:
Patch Set #1, Line 676: for {
Thanks, but this is a busy loop that will print "timer in progress" over and over again. This is not a good example, because nobody should write code like this.
To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.
Attention is currently required from: chandra agung rizky.
chandra agung rizky uploaded patch set #2 to this change.
time: add example for NewTimer function
Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
---
M src/time/example_test.go
1 file changed, 18 insertions(+), 0 deletions(-)
To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.
1 comment:
Patchset:
please take another look my example
To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.
chandra agung rizky abandoned this change.
To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.