-
Notifications
You must be signed in to change notification settings - Fork 33
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
Add handler for peripheral connection cancelled #42
Add handler for peripheral connection cancelled #42
Conversation
- add public `peripheralConnectionCancelledHandler(_:)` settable property - refactor from `.filter(_:).first` to `first(where:)` for optimisation - bump version to 1.0.6 - add project change log
@@ -76,7 +82,7 @@ extension ConnectionService { | |||
/// Disconnects given device. | |||
internal func disconnect(_ peripheral: CBPeripheral) { | |||
if let index = peripherals.firstIndex(where: { $0.peripheral === peripheral }) { | |||
peripherals.remove(at: index) | |||
peripheralsToDisconnect.append(peripherals.remove(at: index)) |
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.
WDYT to extract peripherals.remove(at: index)
to separate variable which could be more readable what is actually going on in here.
/// `error` is nil if disconnect resulted from a call to `cancelPeripheralConnection(_:)`. | ||
/// SeeAlso: https://developer.apple.com/documentation/corebluetooth/cbcentralmanagerdelegate/1518791-centralmanager | ||
if error == nil, | ||
let disconnectedPeripheral = peripheralsToDisconnect.first(where: { $0.peripheral === peripheral }) { |
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.
peripheralsToDisconnect.first(where: { $0.peripheral === peripheral })
is called twice. WDYT to extract it to separate variable which cloud be used in both ifs
? :)
…nce with `peripheral` property identical to given `CBPeripheral` instance
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.
👍 nice
Title
Add handler for peripheral connection cancelled.
Motivation
A project I'm working on needs to be notified when disconnecting a peripheral completes (so after calling
disconnect(_:)
, when CoreBluetooth completes disconnecting).Task Description
peripheralConnectionCancelledHandler(_:)
settable property.filter(_:).first
tofirst(where:)
for optimization