Class: Temporalio::Worker::ThreadPoolExecutor
- Inherits:
-
Object
- Object
- Temporalio::Worker::ThreadPoolExecutor
- Defined in:
- lib/temporalio/worker/thread_pool_executor.rb
Overview
Note:
This is a fixed thread pool that allocated threads eagerly and has an infinite buffer.
A generic fixed thread pool.
This is used to execute multiple activities concurrently and independenty of each other.
Instance Method Summary collapse
-
#initialize(size) ⇒ ThreadPoolExecutor
constructor
Generate new thread pool executor.
-
#schedule { ... } ⇒ Object
Execute a block of code inside of the threads.
-
#shutdown ⇒ Object
Stop the thread pool and wait for all threads to finish work.
Constructor Details
#initialize(size) ⇒ ThreadPoolExecutor
Generate new thread pool executor.
12 13 14 15 16 17 |
# File 'lib/temporalio/worker/thread_pool_executor.rb', line 12 def initialize(size) @queue = Queue.new @pool = Array.new(size) do Thread.new { poll } end end |
Instance Method Details
#schedule { ... } ⇒ Object
Execute a block of code inside of the threads.
22 23 24 |
# File 'lib/temporalio/worker/thread_pool_executor.rb', line 22 def schedule(&block) queue << block end |
#shutdown ⇒ Object
Stop the thread pool and wait for all threads to finish work.
27 28 29 30 31 32 33 |
# File 'lib/temporalio/worker/thread_pool_executor.rb', line 27 def shutdown pool.size.times do schedule { throw EXIT_SYMBOL } end pool.each(&:join) end |