Skip to content

Instantly share code, notes, and snippets.

@niko
Created October 18, 2015 22:18
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 niko/38dfa6371811c75713ad to your computer and use it in GitHub Desktop.
Save niko/38dfa6371811c75713ad to your computer and use it in GitHub Desktop.
# ala https://www.onli-blogging.de/1463/Sinatra-Code-im-Hintergrund-ausfuehren.html
require 'sinatra/base'
require 'thread/pool'
class Transcode
ThreadPool = Thread.pool(2)
def initialize message
ThreadPool.process do
transcode message
end
end
def transcode message
(0..10).each do |i|
puts "#{i}: #{message}"
sleep 1
end
end
end
class API < Sinatra::Application
get '/:m' do
Transcode.new params[:m]
end
run! if app_file == $0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment