mirror of
https://github.com/permissionlesstech/bitchat.git
synced 2026-07-25 09:05:20 +00:00
Replace Thread.sleep with cooperative RunLoop delay in BLEService
Replace blocking Thread.sleep in stopServices() with a cooperative RunLoop-based delay. This allows BLE callbacks to fire during the shutdown delay, improving reliability of leave message transmission. The delay is needed to give the leave message time to transmit before disconnecting peers and stopping the BLE stack.
This commit is contained in:
@@ -521,8 +521,11 @@ final class BLEService: NSObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Give leave message a moment to send
|
// Give leave message a moment to send (cooperative delay allows BLE callbacks to fire)
|
||||||
Thread.sleep(forTimeInterval: TransportConfig.bleThreadSleepWriteShortDelaySeconds)
|
let deadline = Date().addingTimeInterval(TransportConfig.bleThreadSleepWriteShortDelaySeconds)
|
||||||
|
while Date() < deadline {
|
||||||
|
RunLoop.current.run(until: Date().addingTimeInterval(0.01))
|
||||||
|
}
|
||||||
|
|
||||||
// Clear pending notifications
|
// Clear pending notifications
|
||||||
collectionsQueue.sync(flags: .barrier) {
|
collectionsQueue.sync(flags: .barrier) {
|
||||||
|
|||||||
Reference in New Issue
Block a user