Class: RestCore::Timeout
- Inherits:
-
Object
- Object
- RestCore::Timeout
- Includes:
- Middleware
- Defined in:
- lib/rest-core/middleware/timeout.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.members ⇒ Object
6 |
# File 'lib/rest-core/middleware/timeout.rb', line 6 def self.members; [:timeout]; end |
Instance Method Details
#call(env, &k) ⇒ Object
9 10 11 12 |
# File 'lib/rest-core/middleware/timeout.rb', line 9 def call env, &k return app.call(env, &k) if env[DRY] || timeout(env) == 0 process(env, &k) end |
#process(env, &k) ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/rest-core/middleware/timeout.rb', line 14 def process env, &k timer = PromisePool::Timer.new(timeout(env), timeout_error) app.call(env.merge(TIMER => timer), &k) rescue Exception timer.cancel raise end |
#timeout_error ⇒ Object
22 23 24 |
# File 'lib/rest-core/middleware/timeout.rb', line 22 def timeout_error ::Timeout::Error.new('execution expired') end |