Hi, I have a view with an AJAX call to a function in the controller. I want this function to run in the background when the user clicks the link in the view. The function makes calls to another function many times in a loop, and I don''t want these calls to get blocked. Something like this: # This function gets called by the AJAX def loop for i in (1..1000) say(i) end render(:nothing => true) end def say(i) # Code that inserts i into a database table end The view periodically calls a function using ajax, and this function prints stuff from the database table into the user''s view. Currently this ajax call is getting blocked by the loop, so instead of the user seeing the numbers appear as they''re inserted into the database, he sees them all together in the end of the loop. I''m thinking that multithreading could be an idea, but I don''t know how to do it. Any other ideas that would work would be greatly appreciated. Thanks! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
you could try the respond_to_parent plugin. im using that for something similar (uploading multiple files). it basically submits your form to an <iframe> and then allows you to "respond to" the calling page via RJS. http://sean.treadway.info/svn/plugins/responds_to_parent/ ed On 9/6/06, Aditya Rajgarhia <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Hi, > > I have a view with an AJAX call to a function in the controller. I want > this function to run in the background when the user clicks the link in > the view. > > The function makes calls to another function many times in a loop, and I > don''t want these calls to get blocked. Something like this: > > # This function gets called by the AJAX > def loop > for i in (1..1000) > say(i) > end > > render(:nothing => true) > end > > def say(i) > # Code that inserts i into a database table > end > > The view periodically calls a function using ajax, and this function > prints stuff from the database table into the user''s view. > > Currently this ajax call is getting blocked by the loop, so instead of > the user seeing the numbers appear as they''re inserted into the > database, he sees them all together in the end of the loop. > > I''m thinking that multithreading could be an idea, but I don''t know how > to do it. Any other ideas that would work would be greatly appreciated. > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Sep 6, 2006, at 1:42 PM, Aditya Rajgarhia wrote:> > Hi, > > I have a view with an AJAX call to a function in the controller. I > want > this function to run in the background when the user clicks the > link in > the view. > > The function makes calls to another function many times in a loop, > and I > don''t want these calls to get blocked. Something like this: > > # This function gets called by the AJAX > def loop > for i in (1..1000) > say(i) > end > > render(:nothing => true) > end > > def say(i) > # Code that inserts i into a database table > end > > The view periodically calls a function using ajax, and this function > prints stuff from the database table into the user''s view. > > Currently this ajax call is getting blocked by the loop, so instead of > the user seeing the numbers appear as they''re inserted into the > database, he sees them all together in the end of the loop. > > I''m thinking that multithreading could be an idea, but I don''t know > how > to do it. Any other ideas that would work would be greatly > appreciated. > > Thanks!http://backgroundrb.rubyforge.org -Ezra --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
keep in mind that we (my coworker and i) ran into a similar problem and I''m not sure if this is what you might be experiencing. the current http 1.1 spec suggests that clients have no more than 2 simultaneuous connections to a server at any time. browsers such as Firefox and IE adhere to these suggestions but they can be overridden. but thats neither here nor there...the limit is what is important. so anyways, in our situtation, we had to fire off several ajax requests, not knowing about this 2 request limit, and we found that if one of the requests got hung up on the server side, then we were down to 1 and if that one hung up...well, we''re SOL. so what we''ve done is (as Ezra suggests) is use backgroundrb for our intesive work (spawning many threads for said work) and use a periodical request to poll the server for any new data we may need. it works very well and is quite fast. Chris On 9/6/06, Aditya Rajgarhia <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Hi, > > I have a view with an AJAX call to a function in the controller. I want > this function to run in the background when the user clicks the link in > the view. > > The function makes calls to another function many times in a loop, and I > don''t want these calls to get blocked. Something like this: > > # This function gets called by the AJAX > def loop > for i in (1..1000) > say(i) > end > > render(:nothing => true) > end > > def say(i) > # Code that inserts i into a database table > end > > The view periodically calls a function using ajax, and this function > prints stuff from the database table into the user''s view. > > Currently this ajax call is getting blocked by the loop, so instead of > the user seeing the numbers appear as they''re inserted into the > database, he sees them all together in the end of the loop. > > I''m thinking that multithreading could be an idea, but I don''t know how > to do it. Any other ideas that would work would be greatly appreciated. > > Thanks! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Thanks Ezra and Chris, I''ll try the backgroundrb and see how it goes. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---