Class: Concurrent::Channel::Selector::AfterClause

Inherits:
Object
  • Object
show all
Defined in:
lib-edge/concurrent/channel/selector/after_clause.rb

Instance Method Summary collapse

Constructor Details

#initialize(seconds, block) ⇒ AfterClause

Returns a new instance of AfterClause

Raises:

  • (ArgumentError)


10
11
12
13
14
# File 'lib-edge/concurrent/channel/selector/after_clause.rb', line 10

def initialize(seconds, block)
  raise ArgumentError.new('timeout must 0.0 or more') if seconds.to_f < 0.0
  @end = Concurrent.monotonic_time + seconds.to_f
  @block = block
end

Instance Method Details

#executeundocumented



16
17
18
19
20
21
22
23
# File 'lib-edge/concurrent/channel/selector/after_clause.rb', line 16

def execute
  if Concurrent.monotonic_time > @end
    result = @block ? @block.call : nil
    Concurrent::Maybe.just(result)
  else
    Concurrent::Maybe.nothing
  end
end