Skip to content

Commit ef7b4d0

Browse files
hmsrosa
authored andcommitted
Update Pool from Future to Concurrent::Promises
This PR updates SolidQueue::Pool from the deprecated Concurrent::Future to the more "promising" (sorry) Concurrent::Promises API. Rational: The Promises based API is documented as preferred over the Future API. Concurrent::Promises are more performant and deadlock resistant -- Good Things(tm) for SolidQueue. Given Concurrent::Promises where released 2018, there is little "new" or "not battle tested" risk with this change.
1 parent dd3c00f commit ef7b4d0

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/solid_queue/pool.rb

+3-7
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,16 @@ def initialize(size, on_idle: nil)
1818
def post(execution)
1919
available_threads.decrement
2020

21-
future = Concurrent::Future.new(args: [ execution ], executor: executor) do |thread_execution|
21+
Concurrent::Promises.future_on(executor, execution) do |thread_execution|
2222
wrap_in_app_executor do
2323
thread_execution.perform
2424
ensure
2525
available_threads.increment
2626
mutex.synchronize { on_idle.try(:call) if idle? }
2727
end
28+
end.on_rejection! do |e|
29+
handle_thread_error(e)
2830
end
29-
30-
future.add_observer do |_, _, error|
31-
handle_thread_error(error) if error
32-
end
33-
34-
future.execute
3531
end
3632

3733
def idle_threads

0 commit comments

Comments
 (0)