diff --git a/examples/timers/timers.go b/examples/timers/timers.go index d0256e6..693d9c2 100644 --- a/examples/timers/timers.go +++ b/examples/timers/timers.go @@ -21,21 +21,25 @@ func main() { // The `<-timer1.C` blocks on the timer's channel `C` // until it sends a value indicating that the timer - // expired. + // fired. <-timer1.C - fmt.Println("Timer 1 expired") + fmt.Println("Timer 1 fired") // If you just wanted to wait, you could have used // `time.Sleep`. One reason a timer may be useful is - // that you can cancel the timer before it expires. + // that you can cancel the timer before it fires. // Here's an example of that. timer2 := time.NewTimer(time.Second) go func() { <-timer2.C - fmt.Println("Timer 2 expired") + fmt.Println("Timer 2 fired") }() stop2 := timer2.Stop() if stop2 { fmt.Println("Timer 2 stopped") } + + // Give the `timer2` enough time to fire, if it ever + // was going to, to show it is in fact stopped. + time.Sleep(2 * time.Second) } diff --git a/examples/timers/timers.hash b/examples/timers/timers.hash index aa71908..17f3115 100644 --- a/examples/timers/timers.hash +++ b/examples/timers/timers.hash @@ -1,2 +1,2 @@ -fb413c9b1152a30107c53bf0a739a22c0056976b -_cLT2ewHYO8 +36cae12a3ca529e473d7839e9573c3e0a202c2de +gF7VLRz3URM diff --git a/examples/timers/timers.sh b/examples/timers/timers.sh index b4963a9..4f62fbd 100644 --- a/examples/timers/timers.sh +++ b/examples/timers/timers.sh @@ -1,6 +1,6 @@ -// The first timer will expire ~2s after we start the +// The first timer will fire ~2s after we start the // program, but the second should be stopped before it has -// a chance to expire. +// a chance to fire. $ go run timers.go -Timer 1 expired +Timer 1 fired Timer 2 stopped diff --git a/public/timers b/public/timers index 082fb40..6f79311 100644 --- a/public/timers +++ b/public/timers @@ -45,7 +45,7 @@ at tickers.

- +
package main
 
@@ -99,13 +99,13 @@ time. This timer will wait 2 seconds.

The <-timer1.C blocks on the timer’s channel C until it sends a value indicating that the timer -expired.

+fired.

    <-timer1.C
-    fmt.Println("Timer 1 expired")
+    fmt.Println("Timer 1 fired")
 
@@ -115,21 +115,35 @@ expired.

If you just wanted to wait, you could have used time.Sleep. One reason a timer may be useful is -that you can cancel the timer before it expires. +that you can cancel the timer before it fires. Here’s an example of that.

- +
    timer2 := time.NewTimer(time.Second)
     go func() {
         <-timer2.C
-        fmt.Println("Timer 2 expired")
+        fmt.Println("Timer 2 fired")
     }()
     stop2 := timer2.Stop()
     if stop2 {
         fmt.Println("Timer 2 stopped")
     }
+
+ + + + + + +

Give the timer2 enough time to fire, if it ever +was going to, to show it is in fact stopped.

+ + + + +
    time.Sleep(2 * time.Second)
 }
 
@@ -142,15 +156,15 @@ Here’s an example of that.

-

The first timer will expire ~2s after we start the +

The first timer will fire ~2s after we start the program, but the second should be stopped before it has -a chance to expire.

+a chance to fire.

$ go run timers.go
-Timer 1 expired
+Timer 1 fired
 Timer 2 stopped
 
@@ -170,7 +184,7 @@ a chance to expire.