CocoaMQTT
CocoaMQTT copied to clipboard
Change the default DispatchQueue of the CocoaMQTT class to not use `DispatchQueue.main`?
Or at least provide documentation warning that it is the default?
This was the source of rather a lot of problems as I was working under the assumption that it is asynchronous from the main application thread and it was causing deadlocks with my signalling.
Example: Lets say for this example this code runs on the main thread.
let semaphore = DispatchSemaphore(value: 0)
...
mqtt.didConnectAck = { ...
semaphore.signal()
}
mqtt.connect()
semaphore.wait()
mqtt.subscribe(...)
Note that because connect returns immediately after queueing the operation, then immediately halts because the wait call. Because the main thread is waiting for the signal, which is queued AFTER the wait call, it will deadlock.
I'd prefer to use this pattern as to avoid tracing through callback hell.
So please add a warning about this...