Adding Delay/Condition on For Each

I am writing code to perform a curl GET HTML request to get data from a key/value database.

I'm using a dictionary to store the key/values, and cycling through each key using a for each loop.

The issue is that even when I try to wait for a web response, only the last key in the dictionary get populated with data. Not sure how to insert a delay and recheck inside the loop, or if that even works based on how MIT multi-threading works. Wondering if anyone knows of a workaround are possible implementation that will wait to perform the next loop iteration until after the "web.GotText" response has been completed.


You need a work queue, not a loop.

Load the work queue (list) with URLs, then launch your first (item 1) URL's Web Get.

When Web1 GotText fires,

  • process the incoming text based on the URL
  • if the work queue is not empty,
    • remove item 1
  • if the work queue is not empty,
    • launch your first (item 1) URL's Web Get.

AI2 does not like looping for waiting. It goes into a coma.

Thanks ABG.. New to the MIT construct (loops, threads, delays are more my world). Can you point me in the right direction for how to implement a "work queue"? How to start, process, complete, reiterate.. within the MIT App construct?

Much appreciated.


@Taifun has a code sample to download multiple files at his site.

P.S. Found it:

P.P.S. Also see

1 Like

Ahh.. Ok.. I think I see the key idea here. You iterate using a global counter, and call the subsequent "GET" requests in the GOTTEXT event. Makes sense. I'll give it a go.

Thanks again.

FYI, thought I'd post my working code here for future readers.

Thanks again.