@@ -53,12 +53,13 @@ func (c *Client) CreateResource(
5353 if c == nil {
5454 return xerrors .WithStackTrace (errNilClient )
5555 }
56- if ! c . config . AutoRetry () {
56+ call := func ( ctx context. Context ) error {
5757 return xerrors .WithStackTrace (c .createResource (ctx , coordinationNodePath , resource ))
5858 }
59- return retry .Retry (ctx , func (ctx context.Context ) (err error ) {
60- return c .createResource (ctx , coordinationNodePath , resource )
61- }, retry .WithStackTrace ())
59+ if ! c .config .AutoRetry () {
60+ return call (ctx )
61+ }
62+ return retry .Retry (ctx , call , retry .WithStackTrace ())
6263}
6364
6465func (c * Client ) createResource (
@@ -95,12 +96,13 @@ func (c *Client) AlterResource(
9596 if c == nil {
9697 return xerrors .WithStackTrace (errNilClient )
9798 }
98- if ! c . config . AutoRetry () {
99+ call := func ( ctx context. Context ) error {
99100 return xerrors .WithStackTrace (c .alterResource (ctx , coordinationNodePath , resource ))
100101 }
101- return retry .Retry (ctx , func (ctx context.Context ) (err error ) {
102- return xerrors .WithStackTrace (c .alterResource (ctx , coordinationNodePath , resource ))
103- }, retry .WithStackTrace ())
102+ if ! c .config .AutoRetry () {
103+ return call (ctx )
104+ }
105+ return retry .Retry (ctx , call , retry .WithStackTrace ())
104106}
105107
106108func (c * Client ) alterResource (
@@ -137,12 +139,13 @@ func (c *Client) DropResource(
137139 if c == nil {
138140 return xerrors .WithStackTrace (errNilClient )
139141 }
140- if ! c . config . AutoRetry () {
142+ call := func ( ctx context. Context ) error {
141143 return xerrors .WithStackTrace (c .dropResource (ctx , coordinationNodePath , resourcePath ))
142144 }
143- return retry .Retry (ctx , func (ctx context.Context ) (err error ) {
144- return xerrors .WithStackTrace (c .dropResource (ctx , coordinationNodePath , resourcePath ))
145- }, retry .WithStackTrace ())
145+ if ! c .config .AutoRetry () {
146+ return call (ctx )
147+ }
148+ return retry .Retry (ctx , call , retry .WithStackTrace ())
146149}
147150
148151func (c * Client ) dropResource (
@@ -172,14 +175,15 @@ func (c *Client) ListResource(
172175 if c == nil {
173176 return list , xerrors .WithStackTrace (errNilClient )
174177 }
175- if ! c .config .AutoRetry () {
176- list , err = c .listResource (ctx , coordinationNodePath , resourcePath , recursive )
177- return list , xerrors .WithStackTrace (err )
178- }
179- err = retry .Retry (ctx , func (ctx context.Context ) (err error ) {
178+ call := func (ctx context.Context ) error {
180179 list , err = c .listResource (ctx , coordinationNodePath , resourcePath , recursive )
181180 return xerrors .WithStackTrace (err )
182- }, retry .WithIdempotent (true ), retry .WithStackTrace ())
181+ }
182+ if ! c .config .AutoRetry () {
183+ err = call (ctx )
184+ return
185+ }
186+ err = retry .Retry (ctx , call , retry .WithIdempotent (true ), retry .WithStackTrace ())
183187 return
184188}
185189
@@ -222,14 +226,15 @@ func (c *Client) DescribeResource(
222226 if c == nil {
223227 return resource , xerrors .WithStackTrace (errNilClient )
224228 }
225- if ! c .config .AutoRetry () {
226- resource , err = c .describeResource (ctx , coordinationNodePath , resourcePath )
227- return resource , xerrors .WithStackTrace (err )
228- }
229- err = retry .Retry (ctx , func (ctx context.Context ) (err error ) {
229+ call := func (ctx context.Context ) error {
230230 resource , err = c .describeResource (ctx , coordinationNodePath , resourcePath )
231231 return xerrors .WithStackTrace (err )
232- }, retry .WithIdempotent (true ), retry .WithStackTrace ())
232+ }
233+ if ! c .config .AutoRetry () {
234+ err = call (ctx )
235+ return
236+ }
237+ err = retry .Retry (ctx , call , retry .WithIdempotent (true ), retry .WithStackTrace ())
233238 return
234239}
235240
@@ -286,12 +291,13 @@ func (c *Client) AcquireResource(
286291 if c == nil {
287292 return xerrors .WithStackTrace (errNilClient )
288293 }
289- if ! c . config . AutoRetry () {
294+ call := func ( ctx context. Context ) error {
290295 return xerrors .WithStackTrace (c .acquireResource (ctx , coordinationNodePath , resourcePath , amount , opts ... ))
291296 }
292- return retry .Retry (ctx , func (ctx context.Context ) (err error ) {
293- return xerrors .WithStackTrace (c .acquireResource (ctx , coordinationNodePath , resourcePath , amount , opts ... ))
294- }, retry .WithStackTrace ())
297+ if ! c .config .AutoRetry () {
298+ return call (ctx )
299+ }
300+ return retry .Retry (ctx , call , retry .WithStackTrace ())
295301}
296302
297303func (c * Client ) acquireResource (
0 commit comments