Skip to content

Instantly share code, notes, and snippets.

@kazuho
Last active December 22, 2022 02:21
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 kazuho/9539dc13699a0c9d208a2646f3988743 to your computer and use it in GitHub Desktop.
Save kazuho/9539dc13699a0c9d208a2646f3988743 to your computer and use it in GitHub Desktop.
require 'rack'
counter = 0
Thread.new do
loop do
puts "hello, #{counter}"
counter += 1
sleep 1
end
end
app = Proc.new do |env|
[200, {'Content-Type' => 'text/plain; charset=utf-8'}, [counter.to_s]]
end
Rack::Handler::WEBrick.run app, {
:Host => '127.0.0.1',
:Port => 8080,
};
@hsbt
Copy link

hsbt commented Dec 22, 2022

バージョン間で色々と踏んでる気配があるので、これだとどうでしょう?

require "bundler/inline"

gemfile do
  gem "webrick"
  gem "rack", "< 3"
end

require 'rack'

counter = 0

Thread.new do
  loop do
    puts "hello, #{counter}"
    counter += 1
    sleep 1
  end
end

app = Proc.new do |env|
  [200, {'Content-Type' => 'text/plain; charset=utf-8'}, [counter]]
end

Rack::Handler::WEBrick.run [app, {
  :Host => '127.0.0.1',
  :Port => 8080,
}];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment