Currently I'm using an async MQTT library:
I changed all my code to work with events and callbacks:
WiFi-connected
Wifi-disconnected
MQTT-connected
MQTT-disconnected
MQTT-event
It makes the program logic easier to understand.
But I'm no great coder at all. I just use what I find and understand more or less.