class Going::SelectHelper

Helper methods to emulate Go’s Select Cases.

Public Instance Methods

default(&blk) click to toggle source

A case statement that will succeed immediately.

# File lib/going/select_helper.rb, line 11
def default(&blk)
  Channel.new(1) do |ch|
    ch.push(nil, &blk)
  end
end
timeout(seconds, &blk) click to toggle source

A case statement that will succeed after seconds seconds.

# File lib/going/select_helper.rb, line 20
def timeout(seconds, &blk)
  Channel.new do |ch|
    Going.go do
      sleep seconds
      ch.shift
    end
    ch.push(nil, &blk)
  end
end