-
Notifications
You must be signed in to change notification settings - Fork 52
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
Fixes characterist data lost issue #61
Conversation
Just noticed that on #53 a user suggested using a buffered channel too, appart from using Flow, a buffered channel would be nice for reliability. |
@@ -276,7 +276,7 @@ internal class GattConnectionImpl( | |||
} | |||
|
|||
override fun onCharacteristicChanged(gatt: BG, characteristic: BGC) { | |||
launch { characteristicChangedChannel.send(characteristic) } | |||
runBlocking { characteristicChangedChannel.send(characteristic) } |
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.
How is blocking a thread helping here?
Did you try with #53 instead?
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.
That's an awesome question, but I don't have any answer. This just works, rather we like it or not.
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.
Did you try with #53 instead?
Yes, in fact I thought that had solved the issue, but turns out nothing but this solved this crazy behavior.
Hey - just ran into this and have seen the issue before... The problem is that Android re-uses the same In this case, the change to There are a couple of potential solutions, without making it blocking.:
|
Hello @sjp4, thanks a lot for sharing your analysis, I now understand how I'm not going to merge this quick fix because blocking a thread here can lead to other issues in a mobile app, including slower operation in edge cases. I think I'll make a deep copy of library created instances of the |
This PR refers to #60 and fixes the issue.
Also I would like to suggest the use of a buffered channel (
Channel.BUFFERED
) instead of just using the broadcast channel with size 1, to avoid data loss again.