File: //usr/share/ri/3.0.0/system/Ractor/send-i.ri
U:RDoc::AnyMethod[iI" send:ETI"Ractor#send;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"RSend a message to a Ractor's incoming queue to be consumed by Ractor.receive.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"r = Ractor.new do
;TI" value = Ractor.receive
;TI" puts "Received #{value}"
;TI" end
;TI"r.send 'message'
;TI"## Prints: "Received: message"
;T:@format0o;
; [I"YThe method is non-blocking (will return immediately even if the ractor is not ready ;TI"to receive anything):;T@o;; [ I"r = Ractor.new {sleep(5)}
;TI"r.send('test')
;TI"puts "Sent successfully"
;TI"/# Prints: "Sent successfully" immediately
;T;
0o;
; [I"cAttempt to send to ractor which already finished its execution will raise Ractor::ClosedError.;T@o;; [I"r = Ractor.new {}
;TI"r.take
;TI" p r
;TI"*# "#<Ractor:#6 (irb):23 terminated>"
;TI"r.send('test')
;TI"A# Ractor::ClosedError (The incoming-port is already closed)
;T;
0o;
; [I"\If close_incoming was called on the ractor, the method also raises Ractor::ClosedError.;T@o;; [
I"r = Ractor.new do
;TI" sleep(500)
;TI" receive
;TI" end
;TI"r.close_incoming
;TI"r.send('test')
;TI"A# Ractor::ClosedError (The incoming-port is already closed)
;TI"R# The error would be raised immediately, not when ractor will try to receive
;T;
0o;
; [I"]If the +obj+ is unshareable, by default it would be copied into ractor by deep cloning. ;TI"UIf the <tt>move: true</tt> is passed, object is _moved_ into ractor and becomes ;TI"inaccessible to sender.;T@o;; [
I"2r = Ractor.new {puts "Received: #{receive}"}
;TI"msg = 'message'
;TI"r.send(msg, move: true)
;TI"r.take
;TI"p msg
;T;
0o;
; [I"This prints:;T@o;; [I"Received: message
;TI"Vin `p': undefined method `inspect' for #<Ractor::MovedObject:0x000055c99b9b69b8>
;T;
0o;
; [I"NAll references to the object and its parts will become invalid in sender.;T@o;; [I"2r = Ractor.new {puts "Received: #{receive}"}
;TI"s = 'message'
;TI"ary = [s]
;TI"copy = ary.dup
;TI"r.send(ary, move: true)
;TI"
;TI"s.inspect
;TI"G# Ractor::MovedError (can not send any methods to a moved object)
;TI"ary.class
;TI"G# Ractor::MovedError (can not send any methods to a moved object)
;TI"copy.class
;TI"(# => Array, it is different object
;TI"copy[0].inspect
;TI"G# Ractor::MovedError (can not send any methods to a moved object)
;TI"E# ...but its item was still a reference to `s`, which was moved
;T;
0o;
; [I"JIf the object was shareable, <tt>move: true</tt> has no effect on it:;T@o;; [ I"2r = Ractor.new {puts "Received: #{receive}"}
;TI"s = 'message'.freeze
;TI"r.send(s, move: true)
;TI"-s.inspect #=> "message", still available;T;
0:
@fileI"ractor.rb;T:0@omit_headings_from_table_of_contents_below0I"+ractor.send(msg, move: false) -> self
;T0[[I"<<;To;; [ ;@i;0I"(obj, move: false);T@iFI"Ractor;TcRDoc::NormalClass00