瀏覽代碼

close timer sooner

Darien Raymond 8 年之前
父節點
當前提交
23a8da215f
共有 1 個文件被更改,包括 11 次插入4 次删除
  1. 11 4
      common/signal/timer.go

+ 11 - 4
common/signal/timer.go

@@ -21,14 +21,21 @@ func (t *ActivityTimer) UpdateActivity() {
 
 func (t *ActivityTimer) run() {
 	for {
-		time.Sleep(t.timeout)
 		select {
+		case <-time.After(t.timeout):
+			t.cancel()
+			return
 		case <-t.ctx.Done():
 			return
-		case <-t.updated:
 		default:
-			t.cancel()
-			return
+			select {
+			case <-time.After(t.timeout):
+				t.cancel()
+				return
+			case <-t.ctx.Done():
+				return
+			case <-t.updated:
+			}
 		}
 	}
 }