util.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package yamux
  2. import (
  3. "sync"
  4. "time"
  5. )
  6. // Logger is a abstract of *log.Logger
  7. type Logger interface {
  8. Debugf(format string, args ...interface{})
  9. Infof(format string, args ...interface{})
  10. Warnf(format string, args ...interface{})
  11. Errorf(format string, args ...interface{})
  12. }
  13. type discordLogger struct {
  14. }
  15. func (lg *discordLogger) Debugf(format string, args ...interface{}) {
  16. }
  17. func (lg *discordLogger) Infof(format string, args ...interface{}) {
  18. }
  19. func (lg *discordLogger) Warnf(format string, args ...interface{}) {
  20. }
  21. func (lg *discordLogger) Errorf(format string, args ...interface{}) {
  22. }
  23. var (
  24. timerPool = &sync.Pool{
  25. New: func() interface{} {
  26. timer := time.NewTimer(time.Hour * 1e6)
  27. timer.Stop()
  28. return timer
  29. },
  30. }
  31. )
  32. // asyncSendErr is used to try an async send of an error
  33. func asyncSendErr(ch chan error, err error) {
  34. if ch == nil {
  35. return
  36. }
  37. select {
  38. case ch <- err:
  39. default:
  40. }
  41. }
  42. // asyncNotify is used to signal a waiting goroutine
  43. func asyncNotify(ch chan struct{}) {
  44. select {
  45. case ch <- struct{}{}:
  46. default:
  47. }
  48. }
  49. // min computes the minimum of two values
  50. func min(a, b uint32) uint32 {
  51. if a < b {
  52. return a
  53. }
  54. return b
  55. }