@@ -173,21 +173,7 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
173173 defer cancel ()
174174 }
175175
176- closeSession := func (s * session ) {
177- if s == nil {
178- return
179- }
180-
181- closeSessionCtx := xcontext .WithoutDeadline (ctx )
182-
183- if timeout := c .config .DeleteTimeout (); timeout > 0 {
184- var cancel context.CancelFunc
185- createSessionCtx , cancel = xcontext .WithTimeout (closeSessionCtx , timeout )
186- defer cancel ()
187- }
188-
189- _ = s .Close (closeSessionCtx )
190- }
176+ closeSession := onCloseSession (ctx , createSessionCtx , c )
191177
192178 s , err = c .build (createSessionCtx )
193179
@@ -223,6 +209,25 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
223209 }
224210}
225211
212+ // onCloseSession is a closure function that takes a session and performs the actions to close it.
213+ func onCloseSession (ctx , createSessionCtx context.Context , c * Client ) func (s * session ) {
214+ return func (s * session ) {
215+ if s == nil {
216+ return
217+ }
218+
219+ closeSessionCtx := xcontext .WithoutDeadline (ctx )
220+
221+ if timeout := c .config .DeleteTimeout (); timeout > 0 {
222+ var cancel context.CancelFunc
223+ createSessionCtx , cancel = xcontext .WithTimeout (closeSessionCtx , timeout )
224+ defer cancel ()
225+ }
226+
227+ _ = s .Close (closeSessionCtx )
228+ }
229+ }
230+
226231func (c * Client ) CreateSession (ctx context.Context , opts ... table.Option ) (_ table.ClosableSession , err error ) {
227232 if c == nil {
228233 return nil , xerrors .WithStackTrace (errNilClient )
0 commit comments