I don't speak perfect English and I use the Google translator

I had fun with an Arduino with C ++ and now I want to use an ESP32 in Micropython, which allows Wifi connections.
Most tutorials use a blocking loop to connect like:
in C:
While (WIFI.Status ()! = WL_CONNECTED) {
delay (500);
Serial.print (".")}
or in Python:
if not wlan.isconnected ():
print ('connecting to network ...')
wlan.connect ('essid', 'password')
while not wlan.isconnected ():
pass
print ('network config:', wlan.ifconfig ())
If the connection cannot be established, the ESP loops indefinitely and is lost.
However, I saw other Arduino tutorials that used WifiEventHandler.
Example:
WiFiEventHandler gotIpEventHandler, disconnectedEventHandler;
void setup ()
{
Serial.begin (115200);
Serial.println ();
gotIpEventHandler = WiFi.onStationModeGotIP ([] (const WiFiEventStationModeGotIP & event)
{
Serial.print ("Station connected, IP:");
Serial.println (WiFi.localIP ());
});
disconnectedEventHandler = WiFi.onStationModeDisconnected ([] (const WiFiEventStationModeDisconnected & event)
{
Serial.println ("Station disconnected");
});
Serial.printf ("Connecting to% s ... \ n", ssid);
WiFi.begin (ssid, password);
}
I didn't find anything in Micropython. Is it possible to have an equivalent solution?
Thank you in advance