Class: Quickdraw::Worker

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pid:, pipe:) ⇒ Worker

Returns a new instance of Worker.



16
17
18
19
# File 'lib/quickdraw/worker.rb', line 16

def initialize(pid:, pipe:)
	@pid = pid
	@pipe = pipe
end

Class Method Details

.forkObject



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/quickdraw/worker.rb', line 4

def self.fork
	pipe = Quickdraw::Pipe.new

	pid = Process.fork do
		pipe.with_writer do |writer|
			yield(writer)
		end
	end

	new(pid:, pipe:)
end

Instance Method Details

#waitObject



21
22
23
24
25
26
27
# File 'lib/quickdraw/worker.rb', line 21

def wait
	Process.wait(@pid)

	@pipe.with_reader do |reader|
		reader.read
	end
end