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.
 
 
 

71 lines
1.1 KiB

  1. package retry
  2. type Context interface {
  3. get() interface{}
  4. hasResult() bool
  5. hasError() bool
  6. getResult() interface{}
  7. getRetryTimes() int32
  8. getDelayTime() int64
  9. }
  10. type ResultContext struct {
  11. Result interface{}
  12. RetryTimes int32
  13. DelayTime int64
  14. }
  15. func (r *ResultContext) get() interface{} {
  16. return r.Result
  17. }
  18. func (r *ResultContext) hasResult() bool {
  19. return true
  20. }
  21. func (r *ResultContext) hasError() bool {
  22. return false
  23. }
  24. func (r *ResultContext) getResult() interface{} {
  25. return r.Result
  26. }
  27. func (r *ResultContext) getRetryTimes() int32 {
  28. return r.RetryTimes
  29. }
  30. func (r *ResultContext) getDelayTime() int64 {
  31. return r.DelayTime
  32. }
  33. type ErrorContext struct {
  34. Err error
  35. RetryTimes int32
  36. DelayTime int64
  37. }
  38. func (e *ErrorContext) get() interface{} {
  39. return e.Err
  40. }
  41. func (e *ErrorContext) hasResult() bool {
  42. return false
  43. }
  44. func (e *ErrorContext) hasError() bool {
  45. return true
  46. }
  47. func (e *ErrorContext) getResult() interface{} {
  48. return e.Err
  49. }
  50. func (e *ErrorContext) getRetryTimes() int32 {
  51. return e.RetryTimes
  52. }
  53. func (e *ErrorContext) getDelayTime() int64 {
  54. return e.DelayTime
  55. }