Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Pool from Future to Concurrent::Promises #459

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading