Parallelism in Ruby with Ractors

Let’s have a look at the new Ractor API introduced by Ruby 3.0.In classic Ruby style, the Ractor API comes with a set of utilities that make achieving simple things trivial, while also allowing power users to build more complex systems.Figure 1 shows an overview of the basic methods of the API.Ractor.new creates a new actor and its mailbox. The main gotcha here is: the block passed to Ractor.new does not close over the variable scope it was called in. Instead, any variable we want to be available inside the block has to be passed to new as an argument (Figure 1, top-left corner). Check out the documentation for more details on block isolation.Ractor.
Parallelism in Ruby with Ractors #ruby #rubydeveloper #rubyonrails https://rubyonrails.ba/single/parallelism-in-ruby-with-ractors

Nezir Zahirovic

Contractor Ruby On Rails (8+ years) / MCPD .Net / C# / Asp.Net / CSS / SQL / (11 years)

related articles