From b59a6a2ee703e7783e2dfa48ca6f279485a769ed Mon Sep 17 00:00:00 2001 From: liao725636367 <725636367@qq.com> Date: Sun, 29 Sep 2019 18:10:25 +0800 Subject: [PATCH] add func TimeoutRemove for remove time out add func TimeoutRemove for remove time out --- glib/glib.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/glib/glib.go b/glib/glib.go index 2f4bc30f..749a7ddc 100644 --- a/glib/glib.go +++ b/glib/glib.go @@ -1033,14 +1033,22 @@ func IdleAdd(f interface{}, datas ...interface{}) { C._g_idle_add(C.int(id)) } -func TimeoutAdd(interval uint, f interface{}, datas ...interface{}) { +// return id for remove timeout +func TimeoutAdd(interval uint, f interface{}, datas ...interface{}) (id int) { var data interface{} if len(datas) > 0 { data = datas[0] } ctx := &SourcefuncContext{reflect.ValueOf(f), reflect.ValueOf(data)} - id := sourcefunc_contexts.Add(ctx) + id = sourcefunc_contexts.Add(ctx) C._g_timeout_add(C.guint(interval), C.int(id)) + + return +} + +//remove timeout +func TimeoutRemove(id int) { + sourcefunc_contexts.Remove(id) } //-----------------------------------------------------------------------