Class: Bow::ThreadPool
- Inherits:
-
Object
- Object
- Bow::ThreadPool
- Defined in:
- lib/bow/thread_pool.rb
Instance Attribute Summary collapse
-
#max_threads ⇒ Object
Returns the value of attribute max_threads.
-
#queue ⇒ Object
Returns the value of attribute queue.
Instance Method Summary collapse
- #add(&task) ⇒ Object
- #from_enumerable(enumerable, &block) ⇒ Object
-
#initialize(max_threads = 4) {|_self| ... } ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #run ⇒ Object
Constructor Details
#initialize(max_threads = 4) {|_self| ... } ⇒ ThreadPool
Returns a new instance of ThreadPool.
7 8 9 10 11 12 13 14 15 |
# File 'lib/bow/thread_pool.rb', line 7 def initialize(max_threads = 4) @queue = [] @threads = [] @history = [] @max_threads = max_threads return unless block_given? yield(self) run end |
Instance Attribute Details
#max_threads ⇒ Object
Returns the value of attribute max_threads.
5 6 7 |
# File 'lib/bow/thread_pool.rb', line 5 def max_threads @max_threads end |
#queue ⇒ Object
Returns the value of attribute queue.
5 6 7 |
# File 'lib/bow/thread_pool.rb', line 5 def queue @queue end |
Instance Method Details
#add(&task) ⇒ Object
17 18 19 |
# File 'lib/bow/thread_pool.rb', line 17 def add(&task) add_task(task) end |
#from_enumerable(enumerable, &block) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/bow/thread_pool.rb', line 29 def from_enumerable(enumerable, &block) enumerable.each do |params| task = build_task(block, params) add_task(task) end end |
#run ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/bow/thread_pool.rb', line 21 def run @queue.each do |task| wait run_task(task) end wait_for_all end |