Class: ConvenientService::Examples::Standard::V1::Factorial::Utils::Timeout::WithTimeout
- Inherits:
-
Command
- Object
- ConvenientService::Examples::Standard::V1::Factorial::Utils::Timeout::WithTimeout
- Defined in:
- lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb
Defined Under Namespace
Classes: ReturnStruct
Instance Attribute Summary collapse
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#seconds ⇒ Object
readonly
Returns the value of attribute seconds.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(seconds, &block) ⇒ WithTimeout
constructor
A new instance of WithTimeout.
Constructor Details
#initialize(seconds, &block) ⇒ WithTimeout
Returns a new instance of WithTimeout.
15 16 17 18 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 15 def initialize(seconds, &block) @seconds = seconds @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
13 14 15 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 13 def block @block end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
13 14 15 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 13 def seconds @seconds end |
Instance Method Details
#call ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 29 def call return struct(timeout?: false, value: block.call) if seconds.nil? return struct(timeout?: true, value: nil) if seconds.zero? begin struct(timeout?: false, value: ::Timeout.timeout(seconds, &block)) rescue ::Timeout::Error struct(timeout?: true, value: nil) end end |