Class: Yarn::WorkerPool
- Inherits:
-
Object
- Object
- Yarn::WorkerPool
- Includes:
- Logging
- Defined in:
- lib/yarn/worker_pool.rb
Instance Attribute Summary collapse
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
- #create_pool ⇒ Object
-
#initialize(size = 1024) ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #schedule(&block) ⇒ Object
Methods included from Logging
#debug, #log, #output, #timestamp
Constructor Details
#initialize(size = 1024) ⇒ WorkerPool
Returns a new instance of WorkerPool.
14 15 16 17 18 |
# File 'lib/yarn/worker_pool.rb', line 14 def initialize(size=1024) @size = size @workers = create_pool @jobs = Queue.new end |
Instance Attribute Details
#size ⇒ Object (readonly)
Returns the value of attribute size.
12 13 14 |
# File 'lib/yarn/worker_pool.rb', line 12 def size @size end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
12 13 14 |
# File 'lib/yarn/worker_pool.rb', line 12 def workers @workers end |
Instance Method Details
#create_pool ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/yarn/worker_pool.rb', line 20 def create_pool return Array.new(@size) do Thread.new do loop do job = @jobs.pop job.call end end end end |
#schedule(&block) ⇒ Object
31 32 33 |
# File 'lib/yarn/worker_pool.rb', line 31 def schedule(&block) @jobs << block end |