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.
20 21 22 23 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 20 def initialize(seconds, &block) @seconds = seconds @block = block end |
Instance Attribute Details
#block ⇒ Object (readonly)
Returns the value of attribute block.
18 19 20 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 18 def block @block end |
#seconds ⇒ Object (readonly)
Returns the value of attribute seconds.
18 19 20 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 18 def seconds @seconds end |
Instance Method Details
#call ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/convenient_service/examples/standard/v1/factorial/utils/timeout/with_timeout.rb', line 34 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 |