Sha256: 6fff2ee118b0b4d056dc386a0e25e7a73067b281c4e6989c15848665c4a01a63

Contents?: true

Size: 591 Bytes

Versions: 5

Compression:

Stored size: 591 Bytes

Contents

# frozen_string_literal: true

require 'bundler/setup'
require 'polyphony/http'

opts = {
  reuse_addr:  true,
  dont_linger: true
}

def timeout_handler(timeout, &handler)
  ->(req) do
    cancel_after(timeout) { handler.(req) }
  rescue Polyphony::Cancel
    req.respond("timeout\n", ':status' => 502)
  end
end

sleep 0

spin do
  Polyphony::HTTP::Server.serve(
    '0.0.0.0',
    1234,
    opts,
    &timeout_handler(0.1) do |req|
      sleep rand(0.01..0.2)
      req.respond("Hello timeout world!\n")
    end
  )
end

puts "pid: #{Process.pid}"
puts 'Listening on port 1234...'
suspend

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
polyphony-http-0.28 examples/http_server_timeout.rb
polyphony-http-0.27 examples/http_server_timeout.rb
polyphony-http-0.26 examples/http_server_timeout.rb
polyphony-http-0.25 examples/http_server_timeout.rb
polyphony-http-0.24 examples/http_server_timeout.rb