Class: Weary::Middleware::Timeout

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

Instance Method Summary (collapse)

Constructor Details

- (Timeout) initialize(app, time = 15)

Returns a new instance of 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

- (Object) call(env)



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