The following answer from jdantonio is here https://github.com/ruby-concurrency/concurrent-ruby/issues/616
"Most applications should not directly use thread pools. Thread pools are a low-level abstraction intended for internal use. All high-level abstractions in this library (Promise, Actor, etc.) All send jobs to the global thread pool and provide processing exceptions: just select the abstraction that best suits your use case and use it.
If you need to configure your own thread pool and not use a global thread pool, you can still use high-level abstractions. All of them support the option: executor, which allows you to enter your own thread pool. You can then use the exception handling provided by the high-level abstraction.
If you absolutely insist on sending tasks directly to the thread pool, and not using our high-level abstractions (which I categorically reject), just create a task shell. You can find shell examples in all of our high-level abstractions, Rails ActiveJob, Sucker Punch, and other libraries that use our thread pools.
So what about an implementation with Promises? http://ruby-concurrency.imtqy.com/concurrent-ruby/Concurrent/Promise.html In your case, it will look something like this:
promises = [] products.each do |product| new_product = generate_new_prodcut promises << Concurrent::Promise.execute do store_in_db(new_product) end end
Doktor OSwaldo
source share