code.gitea.io/gitea@v1.19.3/modules/util/timer.go (about) 1 // Copyright 2020 The Gitea Authors. All rights reserved. 2 // SPDX-License-Identifier: MIT 3 4 package util 5 6 import ( 7 "time" 8 ) 9 10 // StopTimer is a utility function to safely stop a time.Timer and clean its channel 11 func StopTimer(t *time.Timer) bool { 12 stopped := t.Stop() 13 if !stopped { 14 select { 15 case <-t.C: 16 default: 17 } 18 } 19 return stopped 20 }