util.go 613 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package yamux
  2. import (
  3. "sync"
  4. "time"
  5. )
  6. var (
  7. timerPool = &sync.Pool{
  8. New: func() interface{} {
  9. timer := time.NewTimer(time.Hour * 1e6)
  10. timer.Stop()
  11. return timer
  12. },
  13. }
  14. )
  15. // asyncSendErr is used to try an async send of an error
  16. func asyncSendErr(ch chan error, err error) {
  17. if ch == nil {
  18. return
  19. }
  20. select {
  21. case ch <- err:
  22. default:
  23. }
  24. }
  25. // asyncNotify is used to signal a waiting goroutine
  26. func asyncNotify(ch chan struct{}) {
  27. select {
  28. case ch <- struct{}{}:
  29. default:
  30. }
  31. }
  32. // min computes the minimum of two values
  33. func min(a, b uint32) uint32 {
  34. if a < b {
  35. return a
  36. }
  37. return b
  38. }