title: Can't make a script wait asynchronously for a certain time for the titles to parse before going for the next url
body: <p>I'm trying to create a script in <code>vba</code> using <code>ServerXMLHTTP60</code> to parse the title of the first post from some identical links. My main goal here is to make the script asynchronous along with setting a highest time up to which the script will try before going for the next url.</p>
  
  <p>However, the macro that I've created always goes for the next url when there is a timeout without being able to scrape the titles from the links.</p>
  
  <pre><code>Sub FetchContentWithinSpecificTime()
      Dim oHttp As New ServerXMLHTTP60, HTML As New HTMLDocument
      Dim URL As Variant, Urllist As Variant, t As Date, sResp As Boolean
  
      Urllist = Array( _
          "https://stackoverflow.com/questions/tagged/web-scraping?tab=newest&amp;page=1", _
          "https://stackoverflow.com/questions/tagged/web-scraping?tab=newest&amp;page=2", _
          "https://stackoverflow.com/questions/tagged/web-scraping?tab=newest&amp;page=3", _
          "https://stackoverflow.com/questions/tagged/web-scraping?tab=newest&amp;page=4", _
          "https://stackoverflow.com/questions/tagged/web-scraping?tab=newest&amp;page=5" _
      )
  
      For Each URL In Urllist
          Debug.Print "trying with: " &amp; URL
          With oHttp
              .Open "GET", URL, True
              .setRequestHeader "User-Agent", "Mozilla/5.0"
              .setTimeouts 5000, 5000, 15000, 15000
              .send
              t = Now + TimeValue("00:00:10")
              sResp = False
  
              On Error Resume Next
              Do
                  If .readyState = 4 Then sResp = True: Exit Do
                  If Now &gt; t Then sResp = False: Exit Do
                  DoEvents
              Loop
              On Error GoTo 0
  
              If sResp Then
                  HTML.body.innerHTML = .responseText
                  Debug.Print HTML.querySelector(".question-hyperlink").innerText
              Else:
                  Debug.Print "failed with: " &amp; URL
              End If
          End With
      Next URL
  End Sub
  </code></pre>
  
  <p><strong><em>How can I make a script wait for a certain time for the titles to parse before going for the next url?</em></strong></p>