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 344B

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