Skip to content

Instantly share code, notes, and snippets.

@pmatsinopoulos
Created April 12, 2025 09:24
Show Gist options
  • Select an option

  • Save pmatsinopoulos/5d2f69cdf14f19f9931dc0fd070ea0e6 to your computer and use it in GitHub Desktop.

Select an option

Save pmatsinopoulos/5d2f69cdf14f19f9931dc0fd070ea0e6 to your computer and use it in GitHub Desktop.
Threads Increase Balance for Thread-Process-Safe Code in Ruby on Raiils
user = User.find_by!(email: "panagiotis@matsinopoulos.gr")
threads = []
5.times do
threads << Thread.new do
CalculateUserBalanceJob.perform_now(user.id)
end
end
threads.each(&:join)
user.reload
puts "user_balance: #{user.user_balance.balance}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment