Skip to content

[mobile] make Ready signal for custom listeners#3775

Merged
halseth merged 2 commits into
lightningnetwork:masterfrom
halseth:mobile-listener-signal
Dec 17, 2019
Merged

[mobile] make Ready signal for custom listeners#3775
halseth merged 2 commits into
lightningnetwork:masterfrom
halseth:mobile-listener-signal

Conversation

@halseth
Copy link
Copy Markdown
Contributor

@halseth halseth commented Nov 29, 2019

This allows the caller to know when lnd is ready to accept RPC calls,
which is important for mobile applications where everything happens in
process.

Fixes #3614

This allows the caller to know when lnd is ready to accept RPC calls,
which is inmportant for mobile applications where eveything happens in
process.
Use the custom listeners' Ready channels to provide callbacks to the
mobile application when the gRPC services are ready.

NOTE: this changes the Start() API by adding one extra callback.
@halseth halseth requested a review from bhandras December 3, 2019 13:04
Comment thread mobile/bindings.go
callback.OnResponse([]byte("started"))
// Finally we start two go routines that will call the provided
// callbacks when the RPC servers are ready to accept calls.
go func() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe a simpler approach could be to modify lnd.Main() by adding a started channel as an incoming argument which then could be used to signal that all initialization is finished and we're waiting on <-signal.ShutdownChannel(). WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the unlocker is conditional (it's only started if the wallet is actually locked) you need to know what the state of the individual servers is to be able to react. So there would need to be two started channels which basically comes down to the implemented solution.
I think this is probably the most simple you can get with the current architecture.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, thanks for the clarificaton @guggero .

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@halseth halseth requested a review from guggero December 5, 2019 19:45
Copy link
Copy Markdown
Collaborator

@guggero guggero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and simple change! This makes it much easier to embed lnd, not only on mobile 👍

Comment thread lnd.go
net.Listener

// Ready will be closed by the server listening on Listener.
Ready chan struct{}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we make this <-chan struct{} to make sure we only ever read from it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't really, since we are reading from it one place, and closing it the other place.

Comment thread mobile/bindings.go
callback.OnResponse([]byte("started"))
// Finally we start two go routines that will call the provided
// callbacks when the RPC servers are ready to accept calls.
go func() {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the unlocker is conditional (it's only started if the wallet is actually locked) you need to know what the state of the individual servers is to be able to react. So there would need to be two started channels which basically comes down to the implemented solution.
I think this is probably the most simple you can get with the current architecture.

@bhandras bhandras self-requested a review December 6, 2019 12:36
Copy link
Copy Markdown
Collaborator

@bhandras bhandras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[mobile] Callback when grpc server is ready

3 participants