[go] time: add example for NewTimer function

17 views
Skip to first unread message

chandra agung rizky (Gerrit)

unread,
Aug 10, 2021, 12:45:21 PM8/10/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

chandra agung rizky has uploaded this change for review.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
Gerrit-Change-Number: 341049
Gerrit-PatchSet: 1
Gerrit-Owner: chandra agung rizky <need...@gmail.com>
Gerrit-MessageType: newchange

Ian Lance Taylor (Gerrit)

unread,
Aug 10, 2021, 1:16:07 PM8/10/21
to chandra agung rizky, goph...@pubsubhelper.golang.org, Russ Cox, Go Bot, golang-co...@googlegroups.com

Attention is currently required from: chandra agung rizky.

View Change

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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
Gerrit-Change-Number: 341049
Gerrit-PatchSet: 1
Gerrit-Owner: chandra agung rizky <need...@gmail.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-Attention: chandra agung rizky <need...@gmail.com>
Gerrit-Comment-Date: Tue, 10 Aug 2021 17:16:02 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Gerrit-MessageType: comment

chandra agung rizky (Gerrit)

unread,
Aug 10, 2021, 10:44:23 PM8/10/21
to goph...@pubsubhelper.golang.org, golang-co...@googlegroups.com

Attention is currently required from: chandra agung rizky.

chandra agung rizky uploaded patch set #2 to this change.

View 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.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
Gerrit-Change-Number: 341049
Gerrit-PatchSet: 2
Gerrit-Owner: chandra agung rizky <need...@gmail.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-Attention: chandra agung rizky <need...@gmail.com>
Gerrit-MessageType: newpatchset

chandra agung rizky (Gerrit)

unread,
Aug 10, 2021, 10:45:49 PM8/10/21
to goph...@pubsubhelper.golang.org, Ian Lance Taylor, Russ Cox, Go Bot, golang-co...@googlegroups.com

View Change

1 comment:

To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
Gerrit-Change-Number: 341049
Gerrit-PatchSet: 2
Gerrit-Owner: chandra agung rizky <need...@gmail.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Go Bot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-Comment-Date: Wed, 11 Aug 2021 02:45:44 +0000

chandra agung rizky (Gerrit)

unread,
Jun 25, 2022, 8:21:01 AM6/25/22
to goph...@pubsubhelper.golang.org, Ian Lance Taylor, Russ Cox, Gopher Robot, golang-co...@googlegroups.com

chandra agung rizky abandoned this change.

View Change

Abandoned

To view, visit change 341049. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: go
Gerrit-Branch: master
Gerrit-Change-Id: Ibe8839a0c8dbcc970972af148eb3951fc89fedde
Gerrit-Change-Number: 341049
Gerrit-PatchSet: 2
Gerrit-Owner: chandra agung rizky <need...@gmail.com>
Gerrit-Reviewer: Russ Cox <r...@golang.org>
Gerrit-CC: Gopher Robot <go...@golang.org>
Gerrit-CC: Ian Lance Taylor <ia...@golang.org>
Gerrit-MessageType: abandon
Reply all
Reply to author
Forward
0 new messages