Created
August 8, 2012 16:43
-
-
Save carloslopes/3296532 to your computer and use it in GitHub Desktop.
Handle Thread across routes in sinatra
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
require 'sinatra' | |
set :threads, [] | |
get '/' do | |
settings.threads << Thread.new { sleep 10 } | |
'New thread created' | |
end | |
get '/threads' do | |
erb :threads | |
end | |
__END__ | |
@@ threads | |
The total number of threads is: <%= settings.threads.size %> | |
<% settings.threads.each_with_index do |thread, index| %> | |
<br /> | |
<p>Thread <%= index %> inspect: <%= thread.inspect.gsub!(/<|>/, '<' => '<', '>' => '>') %></p> | |
<p>Thread <%= index %> status: <%= thread.status %></p> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment