 void fetch(BearSSL::WiFiClientSecure *client) {
   client->write("GET / HTTP/1.0\r\nHost: tls.mbed.org\r\nUser-Agent: ESP8266\r\n\r\n");
   client->flush();
-  uint32_t to = millis() + 5000;
+  using oneShot = esp8266::polledTimeout::oneShot;
+  oneShot timeout(5000);
   do {
     char tmp[32];
-    memset(tmp, 0, 32);
     int rlen = client->read((uint8_t*)tmp, sizeof(tmp) - 1);
     yield();
     if (rlen < 0) {
       break;
     }
+    if (rlen == 0) {
+      delay(10); // Give background processes some time
+      continue;
+    }
+    tmp[rlen] = '\0';
     Serial.print(tmp);
-  } while (millis() < to);
+  } while (!timeout);
   client->stop();
   Serial.printf("\n-------\n");
 }


  BearSSL::WiFiClientSecure client;
  client.setInsecure();
  bool mfln = client.probeMaxFragmentLength("tls.mbed.org", 443, 1024);
  Serial.printf("\nConnecting to https://tls.mbed.org\n");
  Serial.printf("MFLN supported: %s\n", mfln ? "yes" : "no");
  if (mfln) {
    client.setBufferSizes(1024, 1024);
  }
  client.connect("tls.mbed.org", 443);
  if (client.connected()) {

// Released to the public domain

#include <ESP8266WiFi.h>
#include <PolledTimeout.h>

#ifndef STASSID
#define STASSID "your-ssid"
