Time. After can be used to do something After a certain time delay,

package main 

import "fmt"
import "time"

func main(){
	for {
		select {
			case <- time.After(1000*time.Millisecond):
				fmt.Println("hello")
		}
	}
}
Copy the code

Each call to time.after generates a new timer and writes chan After duration, which is read in SELECT to delay execution. Output:

hello
hello
hello
hello
hello
hello
hello
hello
hello
......

Copy the code