Class: ShopifyCLI::ThreadPool
- Inherits:
-
Object
- Object
- ShopifyCLI::ThreadPool
- Defined in:
- lib/shopify_cli/thread_pool.rb,
lib/shopify_cli/thread_pool/job.rb
Defined Under Namespace
Classes: Job
Instance Attribute Summary collapse
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
Instance Method Summary collapse
-
#initialize(pool_size: 10) ⇒ ThreadPool
constructor
A new instance of ThreadPool.
- #schedule(job) ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(pool_size: 10) ⇒ ThreadPool
Returns a new instance of ThreadPool.
7 8 9 10 |
# File 'lib/shopify_cli/thread_pool.rb', line 7 def initialize(pool_size: 10) @jobs = Queue.new @pool = Array.new(pool_size) { spawn_thread } end |
Instance Attribute Details
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
5 6 7 |
# File 'lib/shopify_cli/thread_pool.rb', line 5 def errors @errors end |
Instance Method Details
#schedule(job) ⇒ Object
12 13 14 |
# File 'lib/shopify_cli/thread_pool.rb', line 12 def schedule(job) @jobs << job end |
#shutdown ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/shopify_cli/thread_pool.rb', line 16 def shutdown @pool.size.times do schedule(-> { throw(:stop_thread) }) end @pool.map(&:join) ensure @jobs.close end |