In Go language, time packages supplies functionality for determining as well as viewing time. The AfterFunc() function in Go language is used to wait for the duration of time to pass and after that, it calls the defined function “f” in its own go-routine. Moreover, this function is defined under the time package. Here, you need to import the “time” package in order to use these functions.
func AfterFunc(d Duration, f func()) *Timer
Here, *Timer is a pointer to the Timer.
Return Value: It returns a Timer which is then used to cancel the call with the help of its Stop() method.
Function called by AfterFunc() after 3 seconds
Here, the output is returned after 3 seconds and then the returned timer cancels the call to the function using Stop() method. After then the program is exited after the duration of sleep ends.
time to wait time to wait 6 seconds over.... 30 is arriving Done!
In the above example, after the stated duration is over then channel returns its output and the program exits.