Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →
class method
Ractor.yield
(untyped obj, ?move: ::boolish) -> untyped
Ractor.yield(msg, move: false) → nil
ractor.rb
View on GitHub ↗
# File tmp/rubies/ruby-3.4.1/ractor.rb, line 643
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 accepted by take.
Example
r = Ractor.new {Ractor.yield 'Hello from ractor'} puts r.take # Prints: "Hello from ractor"
This 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 the move argument is the same as for send.