Class: Faraday::Interval::Middleware
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::Interval::Middleware
- Defined in:
- lib/faraday/interval.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ Middleware
constructor
A new instance of Middleware.
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, = {}) super(app) @second = [: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 |