Last active
March 29, 2022 09:28
-
-
Save glaucocustodio/1c91060b8f0d27c32f2e2ba5f1c9c4b7 to your computer and use it in GitHub Desktop.
FixedThreadPool / Concurrent::Future usage example (concurrent-ruby gem)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For more: https://github.com/ruby-concurrency/concurrent-ruby | |
num_threads = Concurrent.processor_count # or whatever you prefer like 4 | |
thread_pool = Concurrent::FixedThreadPool.new(num_threads) | |
products = Product.all | |
executors = products.map { |product| | |
Concurrent::Future.execute({executor: thread_pool}) do | |
p "processing #{product.id}" | |
end | |
} | |
executors.map(&:value!) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment