Class: Going::SelectHelper

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/going/select_helper.rb

Overview

Helper methods to emulate Go’s Select Cases.

Instance Method Summary collapse

Instance Method Details

#default(&blk) ⇒ Object

A case statement that will succeed immediately.



11
12
13
14
15
# 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) ⇒ Object

A case statement that will succeed after seconds seconds.



20
21
22
23
24
25
26
27
28
# 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