NordicSemiconductor / Android-BLE-Library

A library that makes working with Bluetooth LE on Android a pleasure. Seriously.
BSD 3-Clause "New" or "Revised" License
2.04k stars 419 forks source link

Bug fix: suspend extension function remains suspended if the request is cancelled #574

Closed muscardinus closed 2 months ago

muscardinus commented 2 months ago

The suspend() extension functions on various Request types will ignore the cancellation instead of throwing an exception when cancelled via a mechanism other then cancelling the coroutine.

In such cases the code that calls suspend() will remain suspended indefinitely.

An example of this is: Call connect from one coroutine (from within a BleManager):

connect(bluetoothDevice)
    .suspend()

While the connect is in progress (within 30 seconds) and before it could succeed, call from another place in the code:

cancelQueue()

While the connection gets cancelled, the first call will remain suspended.

This PR is an attempt to fix the problem.