Class: Braintrust::Internal::ThreadPool::Each
- Inherits:
-
Object
- Object
- Braintrust::Internal::ThreadPool::Each
- Defined in:
- lib/braintrust/internal/thread_pool.rb
Overview
Strategy for iteration without collecting results
Instance Method Summary collapse
- #empty_result ⇒ Object
- #enqueue_sentinel(count) ⇒ Object
- #prepare(items) ⇒ Object
- #result ⇒ Object
- #sequential_run(items, &block) ⇒ Object
- #work_loop(&block) ⇒ Object
Instance Method Details
#empty_result ⇒ Object
50 51 52 |
# File 'lib/braintrust/internal/thread_pool.rb', line 50 def empty_result nil end |
#enqueue_sentinel(count) ⇒ Object
34 35 36 |
# File 'lib/braintrust/internal/thread_pool.rb', line 34 def enqueue_sentinel(count) count.times { @queue << :done } end |
#prepare(items) ⇒ Object
29 30 31 32 |
# File 'lib/braintrust/internal/thread_pool.rb', line 29 def prepare(items) @queue = Queue.new items.each { |item| @queue << item } end |
#result ⇒ Object
46 47 48 |
# File 'lib/braintrust/internal/thread_pool.rb', line 46 def result nil end |
#sequential_run(items, &block) ⇒ Object
54 55 56 57 |
# File 'lib/braintrust/internal/thread_pool.rb', line 54 def sequential_run(items, &block) items.each(&block) nil end |
#work_loop(&block) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/braintrust/internal/thread_pool.rb', line 38 def work_loop(&block) loop do item = @queue.pop break if item == :done block.call(item) end end |