Class: FiberScheduler::Timeout
- Inherits:
-
Object
- Object
- FiberScheduler::Timeout
- Includes:
- Comparable
- Defined in:
- lib/fiber_scheduler/timeout.rb
Constant Summary collapse
- Error =
Class.new(FiberScheduler::Error)
Instance Attribute Summary collapse
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #<=>(other) ⇒ Object
- #call ⇒ Object
- #disable ⇒ Object
- #disabled? ⇒ Boolean
-
#initialize(duration, fiber, method, *args) ⇒ Timeout
constructor
A new instance of Timeout.
- #inspect ⇒ Object
- #interval ⇒ Object
Constructor Details
#initialize(duration, fiber, method, *args) ⇒ Timeout
Returns a new instance of Timeout.
11 12 13 14 15 16 17 18 |
# File 'lib/fiber_scheduler/timeout.rb', line 11 def initialize(duration, fiber, method, *args) @time = Process.clock_gettime(Process::CLOCK_MONOTONIC) + duration @fiber = fiber @method = method @args = args @disabled = nil end |
Instance Attribute Details
#time ⇒ Object (readonly)
Returns the value of attribute time.
9 10 11 |
# File 'lib/fiber_scheduler/timeout.rb', line 9 def time @time end |
Instance Method Details
#<=>(other) ⇒ Object
20 21 22 23 24 |
# File 'lib/fiber_scheduler/timeout.rb', line 20 def <=>(other) raise unless other.is_a?(self.class) @time <=> other.time end |
#call ⇒ Object
26 27 28 29 30 |
# File 'lib/fiber_scheduler/timeout.rb', line 26 def call return unless @fiber.alive? @fiber.public_send(@method, *@args) end |
#disable ⇒ Object
36 37 38 |
# File 'lib/fiber_scheduler/timeout.rb', line 36 def disable @disabled = true end |
#disabled? ⇒ Boolean
40 41 42 |
# File 'lib/fiber_scheduler/timeout.rb', line 40 def disabled? @disabled end |
#inspect ⇒ Object
44 45 46 |
# File 'lib/fiber_scheduler/timeout.rb', line 44 def inspect "#<#{self.class} time=#{@time}>" end |
#interval ⇒ Object
32 33 34 |
# File 'lib/fiber_scheduler/timeout.rb', line 32 def interval @time - Process.clock_gettime(Process::CLOCK_MONOTONIC) end |