Module: Goroutine

Included in:
Channel, Channel::Buffered
Defined in:
lib/goroutine.rb,
lib/goroutine/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#initialize(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/goroutine.rb', line 6

def initialize(*args)
  super(*args)
  @rd, wr = IO.pipe
  rd, @wr = IO.pipe
  go do
    loop do
      IO.select([rd])
      rd.read(1)
      wr.write('.')
    end
  end
end

#popObject Also known as: shift, deq



19
20
21
22
# File 'lib/goroutine.rb', line 19

def pop
  @rd.read(1)
  super
end

#push(val) ⇒ Object Also known as: <<, enq



26
27
28
29
# File 'lib/goroutine.rb', line 26

def push(val)
  @wr.write('.')
  super(val)
end

#to_ioObject



33
34
35
# File 'lib/goroutine.rb', line 33

def to_io
  @rd
end

#waitObject Also known as: ready



37
38
39
# File 'lib/goroutine.rb', line 37

def wait
  IO.select([self])[0]
end