github.com/wangyougui/gf/v2@v2.6.5/os/gtimer/gtimer_z_example_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/wangyougui/gf. 6 7 package gtimer_test 8 9 import ( 10 "context" 11 "fmt" 12 "time" 13 14 "github.com/wangyougui/gf/v2/os/gtimer" 15 ) 16 17 func ExampleAdd() { 18 var ( 19 ctx = context.Background() 20 now = time.Now() 21 interval = 1400 * time.Millisecond 22 ) 23 gtimer.Add(ctx, interval, func(ctx context.Context) { 24 fmt.Println(time.Now(), time.Duration(time.Now().UnixNano()-now.UnixNano())) 25 now = time.Now() 26 }) 27 28 select {} 29 }