Class: Quickdraw::Cluster

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCluster

Returns a new instance of Cluster.



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

def initialize
	@workers = []
end

Class Method Details

.call(n = Etc.nprocessors) ⇒ Object



6
7
8
# File 'lib/quickdraw/cluster.rb', line 6

def self.call(n = Etc.nprocessors, &)
	spawn(n, &).wait
end

.spawn(n = Etc.nprocessors, &block) ⇒ Object



10
11
12
13
14
# File 'lib/quickdraw/cluster.rb', line 10

def self.spawn(n = Etc.nprocessors, &block)
  new.tap do |cluster|
		n.times { cluster.fork(&block) }
	end
end

Instance Method Details

#forkObject



20
21
22
# File 'lib/quickdraw/cluster.rb', line 20

def fork(&)
	@workers << Quickdraw::Worker.fork(&)
end

#waitObject



24
25
26
# File 'lib/quickdraw/cluster.rb', line 24

def wait
	@workers.map(&:wait)
end