27 lines
383 B
Go
27 lines
383 B
Go
package timers
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
)
|
|
|
|
func Timers() {
|
|
t := time.NewTimer(time.Second)
|
|
|
|
go func() {
|
|
<-t.C
|
|
fmt.Println("Goroutine called after 1 second!")
|
|
}()
|
|
|
|
cancelled := t.Stop()
|
|
|
|
if cancelled {
|
|
fmt.Println("Timer cancelled before it got to yield")
|
|
} else {
|
|
fmt.Println("Failed to cancel timer")
|
|
}
|
|
|
|
time.Sleep(2 * time.Second)
|
|
fmt.Println("Program exiting")
|
|
}
|