github.com/ydb-platform/ydb-go-sdk/v3@v3.57.0/trace/retry_gtrace.go (about) 1 // Code generated by gtrace. DO NOT EDIT. 2 3 package trace 4 5 import ( 6 "context" 7 ) 8 9 // retryComposeOptions is a holder of options 10 type retryComposeOptions struct { 11 panicCallback func(e interface{}) 12 } 13 14 // RetryOption specified Retry compose option 15 type RetryComposeOption func(o *retryComposeOptions) 16 17 // WithRetryPanicCallback specified behavior on panic 18 func WithRetryPanicCallback(cb func(e interface{})) RetryComposeOption { 19 return func(o *retryComposeOptions) { 20 o.panicCallback = cb 21 } 22 } 23 24 // Compose returns a new Retry which has functional fields composed both from t and x. 25 func (t *Retry) Compose(x *Retry, opts ...RetryComposeOption) *Retry { 26 var ret Retry 27 options := retryComposeOptions{} 28 for _, opt := range opts { 29 if opt != nil { 30 opt(&options) 31 } 32 } 33 { 34 h1 := t.OnRetry 35 h2 := x.OnRetry 36 ret.OnRetry = func(r RetryLoopStartInfo) func(RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 37 if options.panicCallback != nil { 38 defer func() { 39 if e := recover(); e != nil { 40 options.panicCallback(e) 41 } 42 }() 43 } 44 var r1, r2 func(RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) 45 if h1 != nil { 46 r1 = h1(r) 47 } 48 if h2 != nil { 49 r2 = h2(r) 50 } 51 return func(r RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 52 if options.panicCallback != nil { 53 defer func() { 54 if e := recover(); e != nil { 55 options.panicCallback(e) 56 } 57 }() 58 } 59 var r3, r4 func(RetryLoopDoneInfo) 60 if r1 != nil { 61 r3 = r1(r) 62 } 63 if r2 != nil { 64 r4 = r2(r) 65 } 66 return func(r RetryLoopDoneInfo) { 67 if options.panicCallback != nil { 68 defer func() { 69 if e := recover(); e != nil { 70 options.panicCallback(e) 71 } 72 }() 73 } 74 if r3 != nil { 75 r3(r) 76 } 77 if r4 != nil { 78 r4(r) 79 } 80 } 81 } 82 } 83 } 84 return &ret 85 } 86 func (t *Retry) onRetry(r RetryLoopStartInfo) func(RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 87 fn := t.OnRetry 88 if fn == nil { 89 return func(RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 90 return func(RetryLoopDoneInfo) { 91 return 92 } 93 } 94 } 95 res := fn(r) 96 if res == nil { 97 return func(RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 98 return func(RetryLoopDoneInfo) { 99 return 100 } 101 } 102 } 103 return func(r RetryLoopIntermediateInfo) func(RetryLoopDoneInfo) { 104 res := res(r) 105 if res == nil { 106 return func(RetryLoopDoneInfo) { 107 return 108 } 109 } 110 return res 111 } 112 } 113 func RetryOnRetry(t *Retry, c *context.Context, iD string, call call, label string, idempotent bool, nestedCall bool) func(error) func(attempts int, _ error) { 114 var p RetryLoopStartInfo 115 p.Context = c 116 p.ID = iD 117 p.Call = call 118 p.Label = label 119 p.Idempotent = idempotent 120 p.NestedCall = nestedCall 121 res := t.onRetry(p) 122 return func(e error) func(int, error) { 123 var p RetryLoopIntermediateInfo 124 p.Error = e 125 res := res(p) 126 return func(attempts int, e error) { 127 var p RetryLoopDoneInfo 128 p.Attempts = attempts 129 p.Error = e 130 res(p) 131 } 132 } 133 }