Skip to content

Commit 1b56d3a

Browse files
committed
refactor: use WaitExecControllerRunningTyped over manual type assertions
Replace WaitExecControllerRunning + type assertion pattern with the generic WaitExecControllerRunningTyped across all call sites. Signed-off-by: Christian Stewart <christian@aperture.us>
1 parent 19c2900 commit 1b56d3a

File tree

7 files changed

+351
-16
lines changed

7 files changed

+351
-16
lines changed

daemon/api/api_accept.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ func (a *API) AcceptStream(serv stream_api.SRPCStreamService_AcceptStreamStream)
2424
dir := resolver.NewLoadControllerWithConfig(conf)
2525

2626
// wait until it's ready
27-
val, _, valRef, err := loader.WaitExecControllerRunning(ctx, a.bus, dir, nil)
27+
ctrl, _, ctrlRef, err := loader.WaitExecControllerRunningTyped[*stream_api_accept.Controller](ctx, a.bus, dir, nil)
2828
if err != nil {
2929
return err
3030
}
31-
defer valRef.Release()
31+
defer ctrlRef.Release()
3232

33-
ctrl := val.(*stream_api_accept.Controller)
3433
return ctrl.AttachRPC(stream_api.NewAcceptServerRPC(serv))
3534
}

examples/mesh-chat/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,14 +190,14 @@ func run(listenAddr, dialAddr, keyPath string) error {
190190
}
191191

192192
// Start the UDP transport.
193-
udpCtrl, _, udpRef, err := loader.WaitExecControllerRunning(ctx, b,
193+
tc, _, udpRef, err := loader.WaitExecControllerRunningTyped[*tptc.Controller](ctx, b,
194194
resolver.NewLoadControllerWithConfig(&udptpt.Config{ListenAddr: listenAddr}), nil)
195195
if err != nil {
196196
return err
197197
}
198198
defer udpRef.Release()
199199

200-
tpt, _ := udpCtrl.(*tptc.Controller).GetTransport(ctx)
200+
tpt, _ := tc.GetTransport(ctx)
201201
udp := tpt.(*udptpt.UDP)
202202

203203
// Dial the remote peer if specified.

examples/udp-link/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func execute() error {
9292
defer hr2.Release()
9393

9494
// Execute the UDP transport on the first daemon.
95-
tptc1, _, udpRef1, err := loader.WaitExecControllerRunning(
95+
tc1, _, udpRef1, err := loader.WaitExecControllerRunningTyped[*tptc.Controller](
9696
ctx,
9797
bus1,
9898
resolver.NewLoadControllerWithConfig(&udptpt.Config{
@@ -105,10 +105,10 @@ func execute() error {
105105
}
106106
defer udpRef1.Release()
107107
le.Info("UDP listening on: :5553")
108-
tpt1, _ := tptc1.(*tptc.Controller).GetTransport(ctx)
108+
tpt1, _ := tc1.GetTransport(ctx)
109109

110110
// Execute the UDP transport on the second daemon.
111-
tptc2, _, udpRef2, err := loader.WaitExecControllerRunning(
111+
tc2, _, udpRef2, err := loader.WaitExecControllerRunningTyped[*tptc.Controller](
112112
ctx,
113113
bus2,
114114
resolver.NewLoadControllerWithConfig(&udptpt.Config{
@@ -121,7 +121,7 @@ func execute() error {
121121
}
122122
defer udpRef2.Release()
123123
le.Info("UDP listening on: :5554")
124-
_, _ = tptc2.(*tptc.Controller).GetTransport(ctx)
124+
_, _ = tc2.GetTransport(ctx)
125125

126126
tpt1.(*udptpt.UDP).DialPeer(ctx, p2, (&net.UDPAddr{
127127
IP: net.IP{127, 0, 0, 1},

link/hold-open/hold_open_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func execPeer(ctx context.Context, t *testing.T, tb *testbed.Testbed, conf *inpr
4848
}
4949
conf.TransportPeerId = peerId.String()
5050

51-
tpci1, _, tp1Ref, err := loader.WaitExecControllerRunning(
51+
tpc1, _, tp1Ref, err := loader.WaitExecControllerRunningTyped[*transport_controller.Controller](
5252
ctx,
5353
tb.Bus,
5454
resolver.NewLoadControllerWithConfig(conf),
@@ -57,7 +57,6 @@ func execPeer(ctx context.Context, t *testing.T, tb *testbed.Testbed, conf *inpr
5757
if err != nil {
5858
t.Fatal(err.Error())
5959
}
60-
tpc1 := tpci1.(*transport_controller.Controller)
6160
tpt1, err := tpc1.GetTransport(ctx)
6261
if err != nil {
6362
t.Fatal(err.Error())

0 commit comments

Comments
 (0)