-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example of mounting an async Sinatra app under rails 3
- Loading branch information
Showing
4 changed files
with
14 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Twitter < Sinatra::Base | ||
get '/twitter' do | ||
http = EM::HttpRequest.new("http://search.twitter.com/search?q=rails+3&format=json").get | ||
tweets = ActiveSupport::JSON.decode(http.response) | ||
tweets = tweets['results'].collect {|t| t['text'] }.join("</br>") | ||
tweets | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50c5e4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would there be any advantage to using https://github.com/raggi/async_sinatra here?
50c5e4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, not in this case. Since sinatra is this case is running within a thin server, the net effect is effectively the same.. minus the spaghetti code.
50c5e4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh right, makes sense. It's not as if regular Sinatra is blocking anywhere in your example. And EM::HttpRequest is using 1.9 fibers to avoid callback-littered code, right?
Thanks!
50c5e4f
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, you got it.