Skip to content

Commit

Permalink
Update Pool from Future to Concurrent::Promises
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hms committed Dec 18, 2024
1 parent eb75d09 commit 85703d5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/solid_queue/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,16 @@ def initialize(size, on_idle: nil)
def post(execution)
available_threads.decrement

future = Concurrent::Future.new(args: [ execution ], executor: executor) do |thread_execution|
Concurrent::Promises.future_on(executor, execution) do |thread_execution|
wrap_in_app_executor do
thread_execution.perform
ensure
available_threads.increment
mutex.synchronize { on_idle.try(:call) if idle? }
end
end.on_rejection! do |e|
handle_thread_error(e)
end

future.add_observer do |_, _, error|
handle_thread_error(error) if error
end

future.execute
end

def idle_threads
Expand Down

0 comments on commit 85703d5

Please sign in to comment.