Class: Yahns::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/yahns/worker.rb

Overview

Copyright © 2013, Eric Wong <[email protected]> and all contributors License: GPLv3 or later (www.gnu.org/licenses/gpl-3.0.txt)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(nr) ⇒ Worker

Returns a new instance of Worker.



8
9
10
11
# File 'lib/yahns/worker.rb', line 8

def initialize(nr)
  @nr = nr
  @to_io, @wr = Kgio::Pipe.new
end

Instance Attribute Details

#nrObject

:nodoc:



5
6
7
# File 'lib/yahns/worker.rb', line 5

def nr
  @nr
end

#to_ioObject (readonly)

Returns the value of attribute to_io.



6
7
8
# File 'lib/yahns/worker.rb', line 6

def to_io
  @to_io
end

Instance Method Details

#==(other_nr) ⇒ Object

worker objects may be compared to just plain Integers



34
35
36
# File 'lib/yahns/worker.rb', line 34

def ==(other_nr) # :nodoc:
  @nr == other_nr
end

#atfork_childObject



13
14
15
# File 'lib/yahns/worker.rb', line 13

def atfork_child
  @wr = @wr.close # nil @wr to save space in worker process
end

#atfork_parentObject



17
18
19
20
# File 'lib/yahns/worker.rb', line 17

def atfork_parent
  @to_io = @to_io.close
  self
end

#yahns_stepObject

used in the worker process. This causes the worker to gracefully exit if the master dies unexpectedly.



25
26
27
28
29
30
31
# File 'lib/yahns/worker.rb', line 25

def yahns_step
  if @to_io.kgio_tryread(11) == nil
    Process.kill(:QUIT, $$)
    @to_io.close
  end
  :ignore
end