Class: Faraday::Interval::Middleware

Inherits:
Middleware
  • Object
show all
Defined in:
lib/faraday/interval.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Middleware

Returns a new instance of Middleware.



7
8
9
10
11
# File 'lib/faraday/interval.rb', line 7

def initialize(app, options = {})
  super(app)
  @second = options[:second] || 1
  @last_call = nil
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
# File 'lib/faraday/interval.rb', line 13

def call(env)
  sleep 1 while @last_call && Time.now < @last_call + @second
  @app.call(env).on_complete do
    @last_call = Time.now
  end
end