Post

1) @mike.contribsys.com is a exceedingly clever! 2) I've used Ruby for 12+ years now, and I learned new Hash methods from this article 3) The design of Ruby thread interrupts seem heavily influenced by linux signals 4) My next article "when good threads go bad" will pair nicely with this! 2/11 🧵

0 reposts1 like

The full reasons for that are explained in docs.ruby-lang.org/en/3.4/signa..., and have to do with a concept called "reentrancy". But mike bypasses all of that by using using IO.pipe. The io writer is safe to write to in the trap, so that's all it does, it writes the signal. 4/11 🧵

docs.ruby-lang.orgsignals - Documentation for Ruby 3.4signals: Caveats for implementing Signal. trap callbacks As with implementing signal handlers in C or most other languages, all code passed to Signal.

Meanwhile, the main loop for sidekiq is always waiting on the io reader, calling a blocking method, `wait_readable` in the while loop. Signal received -> write the signal -> wait_readable returns truthy -> while loop runs and calls `handle_signal` with the signal read 5/11 🧵

`handle_signal` can do what it wants! No reentrancy requirements! No special requirements at all in fact - we're back in the regular flow of our program! Super clever. 2) Two weird hash methods big Hash doesn't want you to know... 6/11 🧵