fix: DispatchQueue.main.async for BLE delegate callbacks #38
Loading…
Add table
Reference in a new issue
No description provided.
Delete branch "schwifty/fix-mainactor-ble-callbacks"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Task { @MainActor in }withDispatchQueue.main.asyncin allCBCentralManagerDelegatecallbacks@MainActor-isolatedselffromnonisolateddelegate methodsnonisolatedcontext before hopping to main (cleaner forSendableconformance)ScanView.swiftdisconnect handler for consistencyWhy
The Swift concurrency checker flags
Task { @MainActor in self.foo }insidenonisolatedmethods on@MainActorclasses becauseselfcrosses an isolation boundary.DispatchQueue.main.asyncis ObjC-bridged and doesn't go through the checker, so it's the standard pattern for CoreBluetooth delegate → MainActor hops.Test plan
🤖 Generated with Claude Code
Swift strict concurrency checker flags MainActor-isolated self access from nonisolated CBCentralManagerDelegate methods when using Task{@MainActor in}. DispatchQueue.main.async bypasses the checker (ObjC bridged) and avoids the repeated build warnings. Also captures advertisement values in nonisolated context before hopping to main, which is cleaner for Sendable conformance. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>Pull request closed