Threads, callbacks, and execution context in Ruby

At RubyConf AU 2024, in Sydney, Australia
Cover for Threads, callbacks, and execution context in Ruby

Topics

Share on

When you provide a block to a function in Ruby, do you know when and where that block will be executed? What is safe to do inside a block, and what is dangerous? What is a block, after all? Blocks in Ruby are everywhere, and we’re so used to them that we may even be ignorant of all their power and complexity. Let’s take a look at various code examples and understand what dragons are hidden in Ruby dungeons.

Ruby programmers usually don’t need to think much about blocks… until they have to. As a contributor to Ruby gems that have callback-based API for developers, I’ve found that internal implementation details of these gems affects how these callbacks are executed and resulting behavior can be quite surprising sometimes, and I think that good Ruby developer should know inner workings of blocks to better understand execution flow of complex Ruby programs.

In this talk, I would like to increase public awareness of surprising behavior that can occur when a block is called from different threads, using instance_exec, etc., with examples from open-source gems so everyone can improve their understanding of Ruby program execution details.

Video
Slides

Explore more events

Let's solve your hard problems

Martians at a glance
18
years in business

We're experts at helping developer products grow, with a proven track record in UI design, product iterations, cost-effective scaling, and much more. We'll lay out a strategy before our engineers and designers leap into action.

If you prefer email, write to us at surrender@evilmartians.com