example&comment update

This commit is contained in:
John Guo
2021-11-01 19:46:39 +08:00
parent c0c68d1e46
commit 79a233eb78
14 changed files with 43 additions and 36 deletions

View File

@ -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 {}