Skip to content

Commit 61b9568

Browse files
committed
itest+wasm-client: add WithBlock dial option to client
In this commit, we add a WithBlock client dial option so that the connection is not returned until the connection has been established (ie, handshake is complete). The wasm-client is also updated to spin the `mailboxRPCConnection` off into a goroutine. This is required due to the function being called from within a `js.FuncOf` function (https://pkg.go.dev/syscall/js#FuncOf).
1 parent 8c16134 commit 61b9568

File tree

3 files changed

+30
-19
lines changed

3 files changed

+30
-19
lines changed

cmd/wasm-client/lnd_conn.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ func mailboxRPCConnection(mailboxServer, pairingPhrase string,
4444
grpc.WithDefaultCallOptions(
4545
grpc.MaxCallRecvMsgSize(1024 * 1024 * 200),
4646
),
47+
grpc.WithBlock(),
4748
}
4849

4950
return transportConn.ConnStatus, func() (*grpc.ClientConn, error) {

cmd/wasm-client/main.go

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,36 @@ func (w *wasmClient) ConnectServer(_ js.Value, args []js.Value) interface{} {
188188
}
189189
}
190190

191-
statusChecker, lndConnect, err := mailboxRPCConnection(
192-
mailboxServer, pairingPhrase, localPriv, remotePub,
193-
func(key *btcec.PublicKey) error {
194-
return callJsCallback(
195-
w.cfg.OnRemoteKeyReceive,
196-
hex.EncodeToString(key.SerializeCompressed()),
197-
)
198-
}, func(data []byte) error {
199-
return callJsCallback(
200-
w.cfg.OnAuthData, hex.EncodeToString(data),
201-
)
202-
},
203-
)
204-
if err != nil {
205-
exit(err)
206-
}
191+
// Since the connection function is blocking, we need to spin it off
192+
// in another goroutine here. See https://pkg.go.dev/syscall/js#FuncOf.
193+
go func() {
194+
var err error
195+
statusChecker, lndConnect, err := mailboxRPCConnection(
196+
mailboxServer, pairingPhrase, localPriv, remotePub,
197+
func(key *btcec.PublicKey) error {
198+
return callJsCallback(
199+
w.cfg.OnRemoteKeyReceive,
200+
hex.EncodeToString(
201+
key.SerializeCompressed(),
202+
),
203+
)
204+
}, func(data []byte) error {
205+
return callJsCallback(
206+
w.cfg.OnAuthData, hex.EncodeToString(
207+
data,
208+
),
209+
)
210+
},
211+
)
212+
if err != nil {
213+
exit(err)
214+
}
207215

208-
w.statusChecker = statusChecker
209-
w.lndConn, err = lndConnect()
216+
w.statusChecker = statusChecker
217+
w.lndConn, err = lndConnect()
210218

211-
log.Debugf("WASM client connected to RPC")
219+
log.Debugf("WASM client connected to RPC")
220+
}()
212221

213222
return nil
214223
}

itest/client_harness.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ func (c *clientHarness) start() error {
6666
grpc.WithDefaultCallOptions(
6767
grpc.MaxCallRecvMsgSize(1024 * 1024 * 200),
6868
),
69+
grpc.WithBlock(),
6970
}
7071

7172
http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{

0 commit comments

Comments
 (0)