From 84d9236944b206029299f040ca748ff6b09e6060 Mon Sep 17 00:00:00 2001 From: aceld Date: Tue, 1 Dec 2020 14:44:22 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3issues/85=20ids=E8=B6=8A?= =?UTF-8?q?=E7=95=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ztimer/timerscheduler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ztimer/timerscheduler.go b/ztimer/timerscheduler.go index b486885..9953757 100644 --- a/ztimer/timerscheduler.go +++ b/ztimer/timerscheduler.go @@ -91,13 +91,16 @@ func (this *TimerScheduler) CancelTimer(tid uint32) { this.Unlock() //this.tw.RemoveTimer(tid) 这个方法无效 //删除timerId - var index = 0 + var index = -1 for i := 0; i < len(this.ids); i++ { if this.ids[i] == tid { index = i } } - this.ids = append(this.ids[:index], this.ids[index+1:]...) + + if index > -1 { + this.ids = append(this.ids[:index], this.ids[index+1:]...) + } } //获取计时结束的延迟执行函数通道