Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Perform onConnectAction after assigning Gatt property #72

Merged
merged 2 commits into from
Jul 7, 2020

Conversation

twyatt
Copy link
Member

@twyatt twyatt commented Jun 30, 2020

A developer was unable to perform actions on their Gatt object if they used the reference returned by keepAliveGatt extension function. For example:

private val gatt: KeepAliveGatt = viewModelScope.keepAliveGatt(
    application,
    bluetoothDevice,
    disconnectTimeoutMillis = 5_000L
) {
    discoverServicesOrThrow()
    gatt.writeCharacteristicOrThrow(...) // <-- throws `NotReady` exception :(
}

By performing the OnConnectAction after the internal Gatt property assignment, the KeepAliveGatt has the needed reference and won't throw NotReady if a developer uses their own Gatt reference (provided from keepAliveGatt extension function).

A developer was unable to perform actions on their `Gatt` object if they
used the reference returned by `keepAliveGatt` extension function. For
example:

```
private val gatt: KeepAliveGatt = viewModelScope.keepAliveGatt(
    application,
    bluetoothDevice,
    disconnectTimeoutMillis = 5_000L
) {
    discoverServicesOrThrow()
    gatt.writeCharacteristicOrThrow(...) // throws `NotReady` exception
}
```

By performing the `OnConnectAction` after the internal `Gatt` property
assignment, the `KeepAliveGatt` has the needed reference and won't throw
`NotReady` if a developer uses their own `Gatt` reference (provided from
`keepAliveGatt` extension function).
@twyatt twyatt added this to the 1.0.0 milestone Jul 6, 2020
_gatt = gatt
onConnectAction?.invoke(gatt)
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

@twyatt twyatt merged commit 024fc38 into develop Jul 7, 2020
@twyatt twyatt deleted the twyatt/KeepAliveGatt-onConnectAction branch July 7, 2020 19:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants