I’m writing a small plugin that wraps around a 3rd party device that uses Bluetooth using Swift delegates.
This means that when I fire a method (let’s say readBatteryStatus) the method doesn’t return any value, but instead a second method called (batteryStatusRecived) is fired when the operation is done.
Is there a best practice for handling this? I’ve seen some examples on how to wrap the delegate inside a promise (https://github.com/mxcl/PromiseKit/issues/136#issuecomment-72279182 for example) but they are considered somewhat hacky (according to the writer, I’m not a Swift expert).
In a way PluginCall is a sort of promise, so you could store it on a register handler of some sort, and then when these Bluetooth delegate methods are called , you could call call.reject or call.resolve.