-
Notifications
You must be signed in to change notification settings - Fork 0
/
03-once-timer.go
41 lines (32 loc) · 893 Bytes
/
03-once-timer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
// Golang program to illustrate the usage of
// AfterFunc() function
// Including main package
package main
// Importing fmt and time
import (
"fmt"
"time"
)
// Main function
func main() {
// Defining duration parameter of
// AfterFunc() method
DurationOfTime:= time.Duration(3) * time.Second
// Defining function parameter of
// AfterFunc() method
f:= func() {
// Printed when its called by the
// AfterFunc() method in the time
// stated above
fmt.Println("Function called by "+
"AfterFunc() after 3 seconds")
}
// Calling AfterFunc() method with its
// parameter
Timer1:= time.AfterFunc(DurationOfTime, f)
// Calling stop method
// w.r.to Timer1
defer Timer1.Stop()
// Calling sleep method
time.Sleep(10 * time.Second)
}