Skip to content

Instantly share code, notes, and snippets.

@carloslopes
Created August 8, 2012 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carloslopes/3296532 to your computer and use it in GitHub Desktop.
Save carloslopes/3296532 to your computer and use it in GitHub Desktop.
Handle Thread across routes in sinatra
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!(/<|>/, '<' => '&lt;', '>' => '&gt;') %></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