Rightpoint / RZBluetooth

Core Bluetooth helper library
Other
136 stars 47 forks source link

Allow methods to be called with a timeout parameter instead of using global timeout #102

Open joshbrown-eg opened 5 years ago

joshbrown-eg commented 5 years ago

Issue

As a user, I want to be able to call methods using a timeout parameter, rather than using a global timeout. For example, I'd like to be able to pass timeouts to the following:

-[RZBCentralManager scanForPeripheralsWithServices:options:onDiscoveredPeripheral:]

-[RZBPeripheral writeData:characteristicUUID:serviceUUID:completion:]

...so that I can call them with a different timeouts rather than changing the global timeout every time I want to call a method with a different timeout value.

As it is, I'd have to do something like:

[RZBUserInteraction setTimeout:3];
[centralManager scanForPeripheralsWithServices:...];
[RZBUserInteraction setTimeout:5];
[peripheral writeData:...];

This is painful for multiple reasons, but the biggest concern I have is multithreading. If I change the global timeout in multiple threads, one could affect the other and break what we're trying to do.

Ideally, we'd be able to do this instead:

[centralManager scanForPeripheralsWithServices:<services> timeout:3...];
[peripheral writeData:<data> timeout:5...];
joshbrown-eg commented 5 years ago

We have a fix for this in our fork (egineering-llc/RZBluetooth:master), but there are other changes there awaiting PR reviews in RZBluetooth #92 and #100.