Class: Yahns::Worker
- Inherits:
-
Object
- Object
- Yahns::Worker
- 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
-
#nr ⇒ Object
:nodoc:.
-
#to_io ⇒ Object
readonly
Returns the value of attribute to_io.
Instance Method Summary collapse
-
#==(other_nr) ⇒ Object
worker objects may be compared to just plain Integers.
- #atfork_child ⇒ Object
- #atfork_parent ⇒ Object
-
#initialize(nr) ⇒ Worker
constructor
A new instance of Worker.
-
#yahns_step ⇒ Object
used in the worker process.
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
#nr ⇒ Object
:nodoc:
5 6 7 |
# File 'lib/yahns/worker.rb', line 5 def nr @nr end |
#to_io ⇒ Object (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_child ⇒ Object
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_parent ⇒ Object
17 18 19 20 |
# File 'lib/yahns/worker.rb', line 17 def atfork_parent @to_io = @to_io.close self end |
#yahns_step ⇒ Object
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 |