Class: Slowpoke::Timeout

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

Instance Method Summary collapse

Constructor Details

#initialize(app, service_timeout:) ⇒ Timeout

Returns a new instance of Timeout.



3
4
5
6
7
# File 'lib/slowpoke/timeout.rb', line 3

def initialize(app, service_timeout:)
  @app = app
  @service_timeout = service_timeout
  @middleware = {}
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
# File 'lib/slowpoke/timeout.rb', line 9

def call(env)
  service_timeout = @service_timeout.call(env)
  if service_timeout
    (@middleware[service_timeout] ||= Rack::Timeout.new(@app, service_timeout: service_timeout)).call(env)
  else
    @app.call(env)
  end
end