Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

A long loop and browser freezing. Is there an (delphi) application.processMessages() equivalent in javascript?

462 views
Skip to first unread message

Szymon Wilkołazki

unread,
Dec 17, 2007, 10:23:05 AM12/17/07
to
Hi,

I have a loop that executes in at least few seconds (it waits for about
10 ajax requests to gather all the data).

I would like to tell the browser that the loop is still working and let
the browser do its work.

In past, when I was working in Delphi, I used
application.processMessages() procedure, so my app would stop executing
loop, processed all the windows messages (like mouse clicks etc) and
return to the loop.

Is there any way to pause the loop and let the browser process its
messages, do what the browser usually does, i.e. respond to an click on
the page, and when it's done, return to the loop?


Regards,
Szymon Wilkolazki

Neil Deakin

unread,
Dec 17, 2007, 11:05:52 AM12/17/07
to Szymon Wilkołazki
Szymon Wilkołazki wrote:
> Hi,
>
> I have a loop that executes in at least few seconds (it waits for about
> 10 ajax requests to gather all the data).
>

You should just be making the requests asynchronously, so there
shouldn't be any loop. When the load callback for each is finished,
continue with whatever you need to do.

Neil Deakin

unread,
Dec 17, 2007, 11:05:59 AM12/17/07
to
Szymon Wilkołazki wrote:
> Hi,
>
> I have a loop that executes in at least few seconds (it waits for about
> 10 ajax requests to gather all the data).
>

You should just be making the requests asynchronously, so there

Szymon Wilkołazki

unread,
Dec 18, 2007, 4:28:39 AM12/18/07
to
Neil Deakin wrote:

Yeah, all the requests are asynchronous. When each of them completes,
it increments the counter of responses. I was using loop to wait for
the counter to match number of requests, but I figured better way:

Now I use Prototype's periodicalExecuter to check if the responses
counter match number of requests every second. It does not lock the
browser and do what I want it to do.

Sometimes I still think to much in Delphi and try to translate it to
js, instead of thinking in JS...


Thanks for your reply,
--
Szymon Wilkolazki

Neil Deakin

unread,
Dec 18, 2007, 9:08:55 AM12/18/07
to
Szymon Wilkołazki wrote:
> Neil Deakin wrote:
>> Szymon Wilkołazki wrote:
>>> I have a loop that executes in at least few seconds (it waits for
>>> about 10 ajax requests to gather all the data).
>>>
>>
>> You should just be making the requests asynchronously, so there
>> shouldn't be any loop. When the load callback for each is finished,
>> continue with whatever you need to do.
>
> Yeah, all the requests are asynchronous. When each of them completes, it
> increments the counter of responses. I was using loop to wait for the
> counter to match number of requests, but I figured better way:
>
> Now I use Prototype's periodicalExecuter to check if the responses
> counter match number of requests every second. It does not lock the
> browser and do what I want it to do.
>

A better way may be to just check the counter and call whatever is
necessary in the load callback.

Igor Tandetnik

unread,
Dec 18, 2007, 1:54:01 PM12/18/07
to
Szymon Wilkołazki <wilko...@gmail.com> wrote:
> Neil Deakin wrote:
>> Szymon Wilkołazki wrote:
>>> I have a loop that executes in at least few seconds (it waits for
>>> about 10 ajax requests to gather all the data).
>>>
>>
>> You should just be making the requests asynchronously, so there
>> shouldn't be any loop. When the load callback for each is finished,
>> continue with whatever you need to do.
>
> Yeah, all the requests are asynchronous. When each of them completes,
> it increments the counter of responses. I was using loop to wait for
> the counter to match number of requests

Why? Why not just:

function onResponse() {
++numberOfResponses;
if (numberOfResponses == numberOfRequests) {
allRequestsComplete();
}
}

Igor Tandetnik


0 new messages