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 🧵

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 🧵

`compare_by_identity` sets the hash to compare keys by their reference instead of their value. Not day-to-day useful but a fascinating option, and utilized nicely in Sidekiq 8/11 🧵

Thanks for the reference! I'm gonna check this out more. Zeitwerk is something I think would be super interesting to read through - I bet there's some unique stuff you've had to do in there

0 reposts1 like

No replies yet.