Appropriately using Ruby’s Thread.handle_interrupt
08-Sep-2023 845
Working on GoodJob, I spend a lot of time thinking about multithreaded behavior in Ruby. One piece of Ruby functionality that I don’t see written about very often is Thread.handle_interrupt. Big thanks to John Bachir and Matthew Draper for talking through its usage with me.Some background about interrupts: In Ruby, exceptions can be raised anywhere and at anytime in a thread by other threads (including the main thread, that’s how timeout works). Even rescue and ensure blocks can be interrupted. Everywhere. Most of the time this isn’t something you need to think about (unless you’re using Timeout or rack-timeout or doing explicit multithreaded code). But if you are, it’s important to think and code defensively.
Appropriately using Ruby’s Thread.handle_interrupt #ruby #rubydeveloper #rubyonrails #Appropriately #using #Ruby’s #Thread.handle_interrupt #thread.handle_interrupt https://rubyonrails.ba/link/appropriately-using-ruby-s-thread-handle_interrupt