Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22782

Re: Wait between different Calls (procedures)

Message-ID <37602124.IxAd8SWhiI@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2014-01-25 12:01 +0100
Subject Re: Wait between different Calls (procedures)
Newsgroups comp.lang.javascript
References <d583e3d7-af49-42a3-a979-a48d294537d0@googlegroups.com> <52e142bb$0$9502$9b4e6d93@newsspool1.arcor-online.net> <1680224.8VMzM0OXlI@PointedEars.de> <52e1c579$0$9502$9b4e6d93@newsspool1.arcor-online.net>

Show all headers | View raw


Christoph Michael Becker wrote:

> Thomas 'PointedEars' Lahn wrote:
>> Christoph Michael Becker wrote:
>>> frank.catry@gmail.com wrote:
>>>> i have to populate 3 <select></selects> dom's regarding the content
>>>> of the database. Wehn the user wish to update a record. In my case
>>>> Class, Make and model of a car. However when i try to execute the 3
>>>> getContent calls on the bottom of the code it doesn't work. One by
>>>> one is oké. How can i put a WAIT till finished between the getContent
>>>> calls ?
>>>
>>> Short answer: in a browser environment you can't, cf. "How do I make a
>>> 10 second delay?"[1].
>> 
>> Does the FAQ entry really say that?  If yes, it is incomplete, at best.
> 
> No.  Actually, the FAQ says what you're explaining in the following
> paragraph.  However, I was referring to the last "paragraph" of the OP
> (which I had quickly reformatted to get rid of the flowed format --
> Google Groups, sigh), and the code that was posted there (which I had
> snipped for the same reasons):
> 
> | How can i put a WAIT till finished between the getContent calls ?
> 
> | getContent('theClasses','getClasses.php?key=<?=$oriClasse?>');
> | //Wait ??
> | getContent('theMakes',
> |    'getMakes.php?key=<?=$oriClasse?>&dbvalue=<?=$oriMake?>');

As you can see further below, I was aware of the OP’s complete code when I 
wrote this, so this is not a matter of missing context.  The problem is that 
the OP’s “WAIT till finished” is based on the misconception that the 
function does not return before the requested response has been received.  
AFAICS, nobody else had pointed that out clearly:

You have said that it would not be possible, only possible with synchronous 
XHR (which you recommended correctly to avoid), or a single XHR.  Evertjan. 
has pointed out essentially that the function returns before the response is 
received, and offered a stable, but rather memory-inefficient solution of 
three XHR objects, and the unreliable “solution” of window.setTimeout().

None of you has considered the possibility that the same XHR object could be 
reused, if necessary, if the following requests were triggered by the 
success of receiving the response for the previous one, and each request 
could still be handled asynchronously.  See my other answer.

> I should have added a caveat regarding using Google Groups and a link to
> "Posting Questions and Replies to comp.lang.javascript"[1], though.

I suppose you could have, but why?

>> […]ny waiting can be implemented by moving all parts of the program that
>> need to be waited for into the function body of a function called by
>> window.setTimeout().
>> 
>> In this case, however, the next getContent() call simply needs to be
>> placed into the success event listener assigned by calling the previous
>> one.
   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-- 
PointedEars

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Wait between different Calls (procedures) frank.catry@gmail.com - 2014-01-23 00:20 -0800
  Re: Wait between different Calls (procedures) "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-23 11:06 +0100
  Re: Wait between different Calls (procedures) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-23 17:26 +0100
    Re: Wait between different Calls (procedures) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-24 02:05 +0100
      Re: Wait between different Calls (procedures) Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-24 02:44 +0100
        Re: Wait between different Calls (procedures) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-25 12:01 +0100
  Re: Wait between different Calls (procedures) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-24 02:54 +0100
    Re: Wait between different Calls (procedures) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-25 18:03 +0100

csiph-web