123456789_123456789_123456789_123456789_123456789_

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

Relationships & Source Files
Inherits: Object
Defined in: lib/concurrent-ruby-edge/concurrent/channel/selector/after_clause.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(seconds, block) ⇒ AfterClause

Raises:

  • (ArgumentError)
[ GitHub ]

  
# File 'lib/concurrent-ruby-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

#execute

[ GitHub ]

  
# File 'lib/concurrent-ruby-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