Created
April 12, 2025 09:43
-
-
Save pmatsinopoulos/a19c20b63c996f7a66652e947d4d181a to your computer and use it in GitHub Desktop.
Using Mutex to Give Work to Threads
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
user = User.find_by!(email: "[email protected]") | |
mutex = Thread::Mutex.new | |
threads = [] | |
5.times do | |
threads << Thread.new do | |
CalculateUserBalanceJob.perform_now(user.id, mutex) | |
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