Design a Bluetooth Low Energy (BLE) command handler for an iOS application.
The app needs to send commands to a wearable device over BLE. Commands must be processed strictly one at a time:
-
A command may not be sent until all earlier commands have completed.
-
After sending a command, the handler must wait for either:
-
the expected response from the device, or
-
a timeout.
-
If a command times out, the handler should unblock the queue and continue handling subsequent commands according to a clearly defined failure policy.
-
Multiple parts of the app may enqueue commands concurrently.
-
The design should be suitable for production use in a mobile app, including lifecycle, cancellation, error handling, and testability considerations.
Explain the architecture, key data structures, concurrency model, timeout handling, response matching, and how you would validate the design.