# Periodically call remote is not my friend

**URL:** <https://www.ruby-forum.com/t/periodically-call-remote-is-not-my-friend/109389>\
**Category:** Rails\
**Created:** [July 14, 2007, 12:11am UTC](https://www.ruby-forum.com/t/periodically-call-remote-is-not-my-friend/109389 "2007-07-14T00:11:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [July 14, 2007, 12:11am UTC](https://www.ruby-forum.com/t/periodically-call-remote-is-not-my-friend/109389/1 "2007-07-14T00:11:48Z")

</div>

Hi All,

I have a table in a view (its a partial) that is updated from every 5  
seconds as the shortest frequency to as long as manual by the user based  
on some configuration parameters.

With the periodically\_call\_remote it appears as though I am getting  
subsequent calls going out even though I have one or more pending?  
Although the call is asynchronous I thought calls went out only when the  
completion of previous calls occurs. Meaning, even if my interval might  
have been exceeded it won’t send out the next request until the previous  
comes in. This seems an issue as the load on the server increases the  
probability of missing the interval window increases as well.

Is this not true? If not, how does one manage avoiding parallel calls?  
Would I be better off to dynamically create a single periodic call per  
generation of the partial that is updated as a result of the AJAX call?

Also, if I have a pending call and the user moves to a different page  
before the response comes in I get prototype errors in the firebug  
console. None of them cause crashes etc, but I thought this would be  
benign?

Any information is appreciated on any of these points.

Best Regards,  
Rick

---

<div class="post-metadata">

**Author:** ![rickf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9e8a1a/32.png) [@rickf](https://www.ruby-forum.com/u/rickf)\
**Post date:** [July 14, 2007, 6:23am UTC](https://www.ruby-forum.com/t/periodically-call-remote-is-not-my-friend/109389/2 "2007-07-14T06:23:55Z")

</div>

Rick F. wrote:

> Hi All,
> 
> I have a table in a view (its a partial) that is updated from every 5  
> seconds as the shortest frequency to as long as manual by the user based  
> on some configuration parameters.
> 
> With the periodically\_call\_remote it appears as though I am getting  
> subsequent calls going out even though I have one or more pending?  
> Although the call is asynchronous I thought calls went out only when the  
> completion of previous calls occurs. Meaning, even if my interval might  
> have been exceeded it won’t send out the next request until the previous  
> comes in. This seems an issue as the load on the server increases the  
> probability of missing the interval window increases as well.
> 
> Is this not true? If not, how does one manage avoiding parallel calls?  
> Would I be better off to dynamically create a single periodic call per  
> generation of the partial that is updated as a result of the AJAX call?
> 
> Also, if I have a pending call and the user moves to a different page  
> before the response comes in I get prototype errors in the firebug  
> console. None of them cause crashes etc, but I thought this would be  
> benign?
> 
> Any information is appreciated on any of these points.
> 
> Best Regards,  
> Rick

First of all, why are your ajax requests taking longer than 5 seconds?

Second, asynchronous means that javascript and user interaction will  
continue to take place while the request is being fetched. When the  
timer clicks off again, the new request has no way of knowing the status  
of the old request.a

Third, you can specify a :condition in the options hash, which is a  
javascript expression that must return true in order to send the  
request. So I imagine that you could do something like this:

\<%=  
periodically\_call\_remote(  
:url =\> { :action =\> ‘foo’ },  
:condition =\> “!waitingForFoo”,  
:loading =\> ‘waitingForFoo = true’,  
:complete =\> ‘waitingForFoo = false’  
)  
%\>

This should only send the request if you are not waiting for one.
