So, for example, the problem with this is when you click connect, it won't connect, because still trying, and there is no sync between the UI and system. So, without a single source of truth, the UI can lie without crashing. So, here, the problem is we are not notifying user something is going wrong, because let's say something is going wrong, we will crash the app so that it can recover from memory or help you to put your phone or system into a bad state. Here, we are not crashing or not notifying user. So, it's actually the bad user experience, because user is still trying, why it's not connecting, why it's not connecting, and under the hood, it's just retrying, and there is no indication or no intuitive UI that informs the user, okay, we are trying or something.
Why retries alone fail? So, retry, I mean to say like if something was wrong, you try to fix invisibly in backend or in background, I would say. So, retries from, so, first is retries from, like one disconnect triggers many reconnect. So, for example, you connect it to a device and it disconnect. So, let's say you put like a try catch into that connect and it failed, you again call connect. So, it's like recurring call to connect, disconnect, disconnect, connect. So, nobody coordinates how the things work. The issue is you connect, UI says connect, but it's failing, again connecting, failing, connecting. So, if you're using single states like a new state, and just depending on the Boolean, so, it will be flickering a bit, disconnect, connect, disconnect, connect. I think like whoever is working on a Bluetooth device might have faced this issue, like how hard it is to manage the state between the different connection phases.
Second is duplicate work. Like when you retry or tap on a button or like lifestyle, like a background program, you call connect method just to fix that issue or retry issue. So, the problem is there are three different call sites for the connect and it's hard to trace it unless you put explicit logs or logging there, but I think it's a bad pattern to call a connect method three times just to fix the same retry issue. We'll see how we can fix with the state machine. State machine stale retries. So, for example, you are disconnected and you press on connect. Let's say you press on connect maybe multiple times. Maybe the user is testing or maybe there is a bug, like a logical bug that triggers like multiple connections. So, here what happens is like a first request is in process and still another request is placed. So, there is no check. Okay, if the first request is going on, then wait or terminate that and do the fresh request again. So, the stale request is still like old because it's still pending and it will accumulate the new request. So, it creates a problem because let's say the first request got executed, the second one will get executed. So, unnecessarily there will be multiple callbacks which may put your UI into like a bad state. Blind retries. So, for example, for OTA or setting up a Bluetooth connection and you are trying at the wrong time.
Comments