From 293d7126befaf97bad10faabfe78cc2d30dc5b28 Mon Sep 17 00:00:00 2001 From: songzhibin97 <718428482@qq.com> Date: Sat, 5 Dec 2020 22:49:57 +0800 Subject: [PATCH] Update cmd_Task.go --- server/utils/cmd_Task.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/utils/cmd_Task.go b/server/utils/cmd_Task.go index 06454da0..708be715 100644 --- a/server/utils/cmd_Task.go +++ b/server/utils/cmd_Task.go @@ -73,17 +73,12 @@ func newT(f func(chan struct{}) error) *T { //@description: 添加任务 func (t *T) AddTask() { - if len(t.ch) == 1 { - return - } - t.Lock() - defer t.Unlock() - if len(t.ch) == 1 { + select { + case t.ch <- struct{}{}: + default: // 代表已经有任务了 // 直接丢弃这次任务 - return } - t.ch <- struct{}{} } //@author: [songzhibin97](https://github.com/songzhibin97)