Created
October 18, 2015 22:18
-
-
Save niko/38dfa6371811c75713ad to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# 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