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

Class List Method List File List

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

Inherits:
  Object
  - Object
  - Concurrent::Channel::Selector::AfterClause
  show all
Defined in:
  lib/concurrent/channel/selector/after_clause.rb

## Instance Method Summary (collapse)

- - (undocumented) execute
- - (AfterClause) initialize(seconds, block) constructor

  A new instance of AfterClause.

## Constructor Details

### - (`AfterClause`) initialize(seconds, block)

Returns a new instance of AfterClause

Raises:

- (`ArgumentError`)

    10
    11
    12
    13
    14
    # File 'lib/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

### - (`undocumented`) execute

    16
    17
    18
    19
    20
    21
    22
    23
    # File 'lib/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