bluescreen303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2008-Jan-11 01:44 UTC
waiting for Ajax.Request to return something
Hi, I''m looking for a way to wait for an ajax request to complete before returning something. I know about the (a)synchronous options, but I don''t want to go synchronous, since that makes the browser unresponsive while waiting. I also know about using callbacks. I use this currently but it kind of obfuscates my code. object A needs some data(a name for example) from object B, but B needs to get some stuff (json) from the server to give back the correct answer to A. At the moment I need object A to tell object B "I need your name, call my ''iveGotANameForYou'' - method when you have it. Now, object A can ask for lots of different stuff(not just names), on all kinds of objects, so it has lots and lots of callback-methods for all different kinds of answers. While I like this event-driven approach, it feels like a bit of overkill to me. I would rather have the possibility for object B to defer returning the answer to object A until it''s fetched from the server. That way I can just ask type "var bName = objectB.name()" in objectA without having to write callbacks for every kind of answer. Has anyone found a way around this problem? What I need is a way to ''lock'' just one thread instead of locking up the whole application. Are there any libraries devoted to this? Any other thoughts? Thanks, Mathijs --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Nicolás Sanguinetti
2008-Jan-11 02:26 UTC
Re: waiting for Ajax.Request to return something
On Jan 10, 2008 11:44 PM, bluescreen303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <bluescreen303-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > I''m looking for a way to wait for an ajax request to complete before > returning something. > I know about the (a)synchronous options, but I don''t want to go > synchronous, since that makes the browser unresponsive while waiting. > > I also know about using callbacks. > I use this currently but it kind of obfuscates my code. > > object A needs some data(a name for example) from object B, but B > needs to get some stuff (json) from the server to give back the > correct answer to A. > > At the moment I need object A to tell object B "I need your name, call > my ''iveGotANameForYou'' - method when you have it. > > Now, object A can ask for lots of different stuff(not just names), on > all kinds of objects, so it has lots and lots of callback-methods for > all different kinds of answers.That sounds like object A having lots of responsibilities. That smells to bad class design :)> While I like this event-driven approach, it feels like a bit of > overkill to me. > > I would rather have the possibility for object B to defer returning > the answer to object A until it''s fetched from the server. That way I > can just ask type "var bName = objectB.name()" in objectA without > having to write callbacks for every kind of answer. > > Has anyone found a way around this problem?You can''t do that on js.> What I need is a way to ''lock'' just one thread instead of locking up > the whole application.There''s only one thread for javascript, so locking one thread is equivalent to locking the application anyway.> Are there any libraries devoted to this? > Any other thoughts?There''s jwacs, http://chumsley.org/jwacs, and probably there''s something else similar. That lib let''s you write your script in a superset of javascript that allows for first-order function continuations, and then you "compile" it into normal javascript, if I understood what they are doing correctly (didn''t try it out, just read their docs). So it would let you transparently write what you want, but in the end it''s the same as doing it "by hand". (Plus, the resulting code looks like crap, so it''s gonna be hell to maintain and debug...) Best, -Nicolas> > Thanks, > Mathijs > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---