instance method
Ractor::Port#send
(T obj, ?move: ::boolish) -> self
port.send(msg, move: false) → self
ractor.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.0.0/ractor.rb, line 784
def send obj, move: false
__builtin_cexpr! %q{
ractor_port_send(ec, self, obj, move)
}
end
Sends a message to the port to be accepted by port.receive.
Example
port = Ractor::Port.new r = Ractor.new(port) do |port| port.send 'message' end value = port.receive puts "Received #{value}" # Prints: "Received: message"
The method is non-blocking (it will return immediately even if the ractor that created the port is not ready to receive anything):
Example
port = Ractor::Port.new r = Ractor.new(port) do |port| port.send 'test' puts "Sent successfully" # Prints: "Sent successfully" immediately end
An attempt to send to a closed port will raise Ractor::ClosedError.
Example
r = Ractor.new {Ractor::Port.new} r.join p r # "#<Ractor:#6 (irb):23 terminated>" port = r.value port.send('test') # raise Ractor::ClosedError
If the obj is unshareable, by default it will be copied into the receiving ractor by deep cloning.
If the object is shareable, a reference to the object will be sent to the receiving ractor.