Class: FiberScheduler::Timeout

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/fiber_scheduler/timeout.rb

Constant Summary collapse

Error =
Class.new(FiberScheduler::Error)

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#timeObject (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

#callObject



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

#disableObject



36
37
38
# File 'lib/fiber_scheduler/timeout.rb', line 36

def disable
  @disabled = true
end

#disabled?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/fiber_scheduler/timeout.rb', line 40

def disabled?
  @disabled
end

#inspectObject



44
45
46
# File 'lib/fiber_scheduler/timeout.rb', line 44

def inspect
  "#<#{self.class} time=#{@time}>"
end

#intervalObject



32
33
34
# File 'lib/fiber_scheduler/timeout.rb', line 32

def interval
  @time - Process.clock_gettime(Process::CLOCK_MONOTONIC)
end