End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Ractor.yield
Ractor.yield(msg, move: false) → nil
ractor.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.0.5/ractor.rb, line 626
def self.yield(obj, move: false)
__builtin_cexpr! %q{
ractor_yield(ec, rb_ec_ractor_ptr(ec), obj, move)
}
end
Send a message to the current ractor’s outgoing port to be consumed by take.
Example
r = Ractor.new {Ractor.yield 'Hello from ractor'} puts r.take # Prints: "Hello from ractor"
The method is blocking, and will return only when somebody consumes the sent message.
Example
r = Ractor.new do Ractor.yield 'Hello from ractor' puts "Ractor: after yield" end wait puts "Still not taken" puts r.take
This will print:
Still not taken Hello from ractor Ractor: after yield
If the outgoing port was closed with close_outgoing, the method will raise:
Example
r = Ractor.new do close_outgoing Ractor.yield 'Hello from ractor' end wait # `yield': The outgoing-port is already closed (Ractor::ClosedError)
The meaning of move argument is the same as for send.