The previous recipe describes how to execute the code periodically. This recipe will show you how to execute the code with a delay.
Waiting a certain amount of time
How to do it...
- Open the console and create the folder chapter04/recipe10.
- Navigate to the directory.
- Create the delay.go file with the following content:
package main
import (
"fmt"
"sync"
"time"
)
func main() {
t := time.NewTimer(3 * time.Second)
fmt.Printf("Start waiting at %v\n",
time.Now().Format(time.UnixDate))
<-t.C
fmt.Printf("Code executed at %v\n",
time.Now().Format...