Skip to content

Commit e9d1ce8

Browse files
authored
Revert "feat: add OnClose hooks in Client instance (#1054)"
This reverts commit 16dd095.
1 parent 295fa7e commit e9d1ce8

2 files changed

Lines changed: 0 additions & 58 deletions

File tree

client.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ type (
9595
// SuccessHook type is for reacting to request success
9696
SuccessHook func(*Client, *Response)
9797

98-
// CloseHook type is for reacting to client closing
99-
CloseHook func()
100-
10198
// RequestFunc type is for extended manipulation of the Request instance
10299
RequestFunc func(*Request) *Request
103100

@@ -218,7 +215,6 @@ type Client struct {
218215
invalidHooks []ErrorHook
219216
panicHooks []ErrorHook
220217
successHooks []SuccessHook
221-
closeHooks []CloseHook
222218
contentTypeEncoders map[string]ContentTypeEncoder
223219
contentTypeDecoders map[string]ContentTypeDecoder
224220
contentDecompresserKeys []string
@@ -842,15 +838,6 @@ func (c *Client) OnPanic(h ErrorHook) *Client {
842838
return c
843839
}
844840

845-
// OnClose method adds a callback that will be run whenever the client is closed.
846-
// The hooks are executed in the order they were registered.
847-
func (c *Client) OnClose(h CloseHook) *Client {
848-
c.lock.Lock()
849-
defer c.lock.Unlock()
850-
c.closeHooks = append(c.closeHooks, h)
851-
return c
852-
}
853-
854841
// ContentTypeEncoders method returns all the registered content type encoders.
855842
func (c *Client) ContentTypeEncoders() map[string]ContentTypeEncoder {
856843
c.lock.RLock()
@@ -2234,14 +2221,10 @@ func (c *Client) Clone(ctx context.Context) *Client {
22342221

22352222
// Close method performs cleanup and closure activities on the client instance
22362223
func (c *Client) Close() error {
2237-
// Execute close hooks first
2238-
c.onCloseHooks()
2239-
22402224
if c.LoadBalancer() != nil {
22412225
silently(c.LoadBalancer().Close())
22422226
}
22432227
close(c.certWatcherStopChan)
2244-
22452228
return nil
22462229
}
22472230

@@ -2398,15 +2381,6 @@ func (c *Client) onInvalidHooks(req *Request, err error) {
23982381
}
23992382
}
24002383

2401-
// Helper to run closeHooks hooks.
2402-
func (c *Client) onCloseHooks() {
2403-
c.lock.RLock()
2404-
defer c.lock.RUnlock()
2405-
for _, h := range c.closeHooks {
2406-
h()
2407-
}
2408-
}
2409-
24102384
func (c *Client) debugf(format string, v ...any) {
24112385
if c.IsDebug() {
24122386
c.Logger().Debugf(format, v...)

client_test.go

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,35 +1524,3 @@ func TestClientCircuitBreaker(t *testing.T) {
15241524
assertError(t, err)
15251525
assertEqual(t, uint32(1), c.circuitBreaker.failureCount.Load())
15261526
}
1527-
1528-
func TestClientOnClose(t *testing.T) {
1529-
var hookExecuted bool
1530-
1531-
c := dcnl()
1532-
c.OnClose(func() {
1533-
hookExecuted = true
1534-
})
1535-
1536-
err := c.Close()
1537-
assertNil(t, err)
1538-
assertEqual(t, true, hookExecuted)
1539-
}
1540-
1541-
func TestClientOnCloseMultipleHooks(t *testing.T) {
1542-
var executionOrder []string
1543-
1544-
c := dcnl()
1545-
c.OnClose(func() {
1546-
executionOrder = append(executionOrder, "first")
1547-
})
1548-
c.OnClose(func() {
1549-
executionOrder = append(executionOrder, "second")
1550-
})
1551-
c.OnClose(func() {
1552-
executionOrder = append(executionOrder, "third")
1553-
})
1554-
1555-
err := c.Close()
1556-
assertNil(t, err)
1557-
assertEqual(t, []string{"first", "second", "third"}, executionOrder)
1558-
}

0 commit comments

Comments
 (0)