You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

timer.go 416B

123456789101112131415161718192021
  1. // Copyright 2020 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package util
  5. import (
  6. "time"
  7. )
  8. // StopTimer is a utility function to safely stop a time.Timer and clean its channel
  9. func StopTimer(t *time.Timer) bool {
  10. stopped := t.Stop()
  11. if !stopped {
  12. select {
  13. case <-t.C:
  14. default:
  15. }
  16. }
  17. return stopped
  18. }