Skip to content

Commit 025d2b5

Browse files
committed
take constructor approach instead of callback
1 parent 2a8ce4c commit 025d2b5

File tree

7 files changed

+391
-338
lines changed

7 files changed

+391
-338
lines changed

pkg/loop/internal/net/broker.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,6 @@ func (b *BrokerExt) NewClientConn(name string, newClient newClientFn) *clientCon
8383
}
8484
}
8585

86-
// NewClientConnWithCallback return a new *clientConn backed by this *BrokerExt with a refresh callback.
87-
func (b *BrokerExt) NewClientConnWithCallback(name string, newClient newClientFn, refreshCallback RefreshCallback) *clientConn {
88-
return &clientConn{
89-
BrokerExt: b.WithName(name),
90-
newClient: newClient,
91-
name: name,
92-
refreshCallback: refreshCallback,
93-
}
94-
}
95-
9686
func (b *BrokerExt) StopCtx() (context.Context, context.CancelFunc) {
9787
return utils.ContextFromChan(b.StopCh)
9888
}

pkg/loop/internal/net/client.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ var _ grpc.ClientConnInterface = (*clientConn)(nil)
3535
// newClientFn returns a new client connection id to dial, and a set of Resource dependencies to close.
3636
type newClientFn func(context.Context) (id uint32, deps Resources, err error)
3737

38-
// RefreshCallback is called after a successful refresh, but before the connection is made available.
39-
// This allows clients to perform state management operations before the refreshed client is used again.
40-
type RefreshCallback func(ctx context.Context) error
41-
4238
// clientConn is a [grpc.ClientConnInterface] backed by a [*grpc.ClientConn] which can be recreated and swapped out
4339
// via the provided [newClientFn].
4440
// New instances should be created via BrokerExt.NewClientConn.
@@ -47,10 +43,9 @@ type clientConn struct {
4743
newClient newClientFn
4844
name string
4945

50-
mu sync.RWMutex
51-
deps Resources
52-
cc *grpc.ClientConn
53-
refreshCallback RefreshCallback
46+
mu sync.RWMutex
47+
deps Resources
48+
cc *grpc.ClientConn
5449
}
5550

5651
func (c *clientConn) Invoke(ctx context.Context, method string, args interface{}, reply interface{}, opts ...grpc.CallOption) error {
@@ -155,12 +150,5 @@ func (c *clientConn) refresh(ctx context.Context, orig *grpc.ClientConn) *grpc.C
155150
}
156151
}
157152

158-
if c.refreshCallback != nil {
159-
if err := c.refreshCallback(ctx); err != nil {
160-
// Log error but make the refreshed connection available anyway.
161-
c.Logger.Errorw("Refresh callback failed", "err", err)
162-
}
163-
}
164-
165153
return c.cc
166154
}

0 commit comments

Comments
 (0)