-
Notifications
You must be signed in to change notification settings - Fork 22
Mobile: spin off blocking RPCConnection call into goroutine #61
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question about concurrency, otherwise looks good to me.
mobile/mobile.go
Outdated
if !ok { | ||
return fmt.Errorf("unknown namespace: %s", nameSpace) | ||
} | ||
|
||
// Since the connection function is blocking, we need to spin it off | ||
// in another goroutine here. See https://pkg.go.dev/syscall/js#FuncOf. | ||
go func() { | ||
mcMutex.Lock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this changes the behavior that much. It's still a global lock, just narrower in its scope. If you want to have a lock per namespace, one way would be to have a map of mutexes (that itself is guarded by mMutex
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guggero Took this approach and pushed a change. LMK know what you think. Not sure if I have to explicitly check for each mutex here, but I included the check for now
5efa91c
to
789f850
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, looking at it more closely this can be simplified by just putting the lock into the mobile client itself. It's easier to show in code, so this is my suggestion: guggero/lightning-node-connect@7f3323d
1859459
to
6ba220c
Compare
mobile: suggest improvements to locking
6ba220c
to
1d483e8
Compare
Tested on both Android and iOS with multiple connections |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🎉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just one small nit about embedding the mutex into the struct rather. But non-blocking :)
No description provided.