mirror of
https://gitee.com/johng/gf
synced 2026-07-08 14:39:50 +08:00
example&comment update
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/gogf/gf/v2/os/gfsnotify"
|
||||
@ -9,8 +10,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
var (
|
||||
ctx = context.Background()
|
||||
)
|
||||
callback, err := gfsnotify.Add("/home/john/temp", func(event *gfsnotify.Event) {
|
||||
glog.Print("callback")
|
||||
glog.Print(ctx, "callback")
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -19,9 +23,9 @@ func main() {
|
||||
// 在此期间创建文件、目录、修改文件、删除文件
|
||||
|
||||
// 20秒后移除回调函数注册,所有的回调都移除,不再有任何打印信息输出
|
||||
gtimer.SetTimeout(20*time.Second, func() {
|
||||
gtimer.SetTimeout(ctx, 20*time.Second, func(ctx context.Context) {
|
||||
gfsnotify.RemoveCallback(callback.Id)
|
||||
glog.Print("remove callback")
|
||||
glog.Print(ctx, "remove callback")
|
||||
})
|
||||
|
||||
select {}
|
||||
|
||||
Reference in New Issue
Block a user