Parallelism in Ruby with Ractors
04-Feb-2021 1119
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 #Parallelism #Ractors https://rubyonrails.ba/link/parallelism-in-ruby-with-ractors