Push multiple messages to a subscriber #23
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pushes multiple messages to a subscriber where more than one delimiter exists in a message.
As an example, let's assume that in our app, we've called
bluetoothSerial.subscribe('\n', success, failure);
If MEGBluetoothSerial::bleDidReceiveData gets sent a string of "1\n2\n" our success callback above gets called with "1". "2\n" remains in the buffer.
If MEGBluetoothSerial::bleDidReceiveData then gets sent a string of "3\n", our success callback above gets called with "2", as it's now next in the buffer
As you can see, as soon as MEGBluetoothSerial::bleDidReceiveData gets sent data with more than one delimiter, our callback will be out of phase with the message received.
This pull request ensures that MEGBluetoothSerial::bleDidReceiveData will fire our success callback for each delimited message.
P.S. This is my first pull request, so apologies in advance if I've mucked it up or done something wrong. Let me know if I need to change it somehow.