Class: Gem::Dependent::Parallel::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/rubygems/dependent/parallel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(read, write, pid) ⇒ Worker

Returns a new instance of Worker.



34
35
36
# File 'lib/rubygems/dependent/parallel.rb', line 34

def initialize(read, write, pid)
  @read, @write, @pid = read, write, pid
end

Instance Attribute Details

#pidObject (readonly)

Returns the value of attribute pid.



33
34
35
# File 'lib/rubygems/dependent/parallel.rb', line 33

def pid
  @pid
end

#readObject (readonly)

Returns the value of attribute read.



33
34
35
# File 'lib/rubygems/dependent/parallel.rb', line 33

def read
  @read
end

#writeObject (readonly)

Returns the value of attribute write.



33
34
35
# File 'lib/rubygems/dependent/parallel.rb', line 33

def write
  @write
end

Instance Method Details

#close_pipesObject



38
39
40
41
# File 'lib/rubygems/dependent/parallel.rb', line 38

def close_pipes
  read.close
  write.close
end

#waitObject



43
44
45
46
47
# File 'lib/rubygems/dependent/parallel.rb', line 43

def wait
  Process.wait(pid)
rescue Interrupt
  # process died
end

#work(index) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rubygems/dependent/parallel.rb', line 49

def work(index)
  begin
    Marshal.dump(index, write)
  rescue Errno::EPIPE
    raise DeadWorker
  end

  begin
    Marshal.load(read)
  rescue EOFError
    raise Parallel::DeadWorker
  end
end