generated from StanfordBDHG/SwiftPackageTemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Peripheral discovery as async operations (#46)
# Peripheral discovery as async operations ## ♻️ Current situation & Problem While SpeziBluetooth exposes all Peripheral interactions as async/await-based operations, embracing Swift Concurrency, it doesn't always do that for internal operations. For example, the initial discovering phase does not use async/await and instead performs checks within the delegate method implementations. This has the result, that code is relatively hard to read as state checking is scattered around the implementation (e.g., we check in several places if we can call `signalFullyDiscovered()`). This PR improves code readability and state management by making all peripheral interactions relying on async/await-based operations. Operations like service and characteristic discovery can now be performed via an async call. Further, enabling notifications can be performed using an async method call. As a result, all code relating to service discovery is now placed in one async method. Potential errors can be easily propagated back to the `connect` continuation making it possible to properly communicate if a connecting attempt failed (e.g., because we weren't able to subscribe to a characteristic after several tries). Further, this PR changes the point in time when we consider a device fully connected. While we are still subscribing to characteristic notifications, the device will still report `connecting` state. This makes it easier for library users to determine when a device is fully ready. ## ⚙️ Release Notes * Internal restructure of BluetoothPeripheral resulting in better maintainable code. * Errors from the service discovery are now reported back to the `connect()` method call and errors are thrown into the continuation. An unsuccessful discovery will result in the device being disconnected. * Device is considered `connecting` while characteristic notifications are enabled. * Fixed an issue were the onChange handler would not be called if the `initial` parameter was set to `false` if the characteristic is notify-only or an error occurred in the initial read. * `DiscoveryCriteria` now supports specifying multiple advertised services. * Fixed a potential race condition when enabling notifications for a `@Characteristic` before the peripheral was injected. * `CurrentTimeService/synchronizeDeviceTime(now:threshold:)` is now `async throws` allowing to inspect potential errors. ## 📚 Documentation Documentation was updated to reflect changes in this PR. ## ✅ Testing Existing testing infrastructure was used to validate correctness. ## 📝 Code of Conduct & Contributing Guidelines By submitting creating this pull request, you agree to follow our [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md): - [x] I agree to follow the [Code of Conduct](https://github.com/StanfordSpezi/.github/blob/main/CODE_OF_CONDUCT.md) and [Contributing Guidelines](https://github.com/StanfordSpezi/.github/blob/main/CONTRIBUTING.md).
- Loading branch information
Showing
45 changed files
with
1,198 additions
and
489 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.