Class: Weary::Middleware::Timeout

Inherits:
Object
  • Object
show all
Defined in:
lib/weary/middleware/timeout.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, time = 15) ⇒ Timeout



7
8
9
10
# File 'lib/weary/middleware/timeout.rb', line 7

def initialize(app, time = 15)
  @app = app
  @time = time
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/weary/middleware/timeout.rb', line 12

def call(env)
  begin
    ::Timeout.timeout(@time) { @app.call(env) }
  rescue ::Timeout::Error => e
    [504, {'Content-Type' => "text/plain"}, [e.message]]
  end
end