On Dec 2, 10:48 pm, Dmytrii Nagirniak <[email protected]> wrote: > So Fibers are basically the only option here (with or without em-synchrony)? > Which means no Ruby 1.8. I guess I can sacrifice that but would prefer not to.
There is a 1.8 fiber library, which I did manage to use and get EM working: https://github.com/tmm1/fiber18 Mind you, I do think it's going to be simpler to use 1.9 > So for example, in the typical Rails app this code would not care about > sync/async: > # in the controller > post = Post.find(123) # Executes HTTP request, but doesn't block > # A bit further, maybe in the view: > post.title # Here it either waits for the request to finish or, if it's > already finished, just returns the value The main structural change you'll need to make to your code is to separate the first part from the second part. Don't do the view rendering (the response), until the callback you register in the first part has been called. Refactoring your code in arbitrary pseudo-code: response = Post.find(123) response.callback do |result| render result # using post.title, etc... end -- You received this message because you are subscribed to the Google Groups "Ruby or Rails Oceania" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rails-oceania?hl=en.
