File: //usr/share/ri/3.0.0/system/Ractor/receive-c.ri
U:RDoc::AnyMethod[iI"receive:ETI"Ractor::receive;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"\Receive an incoming message from the current Ractor's incoming port's queue, which was ;TI"sent there by #send.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"r = Ractor.new do
;TI" v1 = Ractor.receive
;TI" puts "Received: #{v1}"
;TI" end
;TI"r.send('message1')
;TI"r.take
;TI"2# Here will be printed: "Received: message1"
;T:@format0o;
; [I"BAlternatively, private instance method +receive+ may be used:;T@o;; [I"r = Ractor.new do
;TI" v1 = receive
;TI" puts "Received: #{v1}"
;TI" end
;TI"r.send('message1')
;TI"r.take
;TI"2# Here will be printed: "Received: message1"
;T;
0o;
; [I"-The method blocks if the queue is empty.;T@o;; [I"r = Ractor.new do
;TI"# puts "Before first receive"
;TI" v1 = Ractor.receive
;TI" puts "Received: #{v1}"
;TI" v2 = Ractor.receive
;TI" puts "Received: #{v2}"
;TI" end
;TI"
wait
;TI"puts "Still not received"
;TI"r.send('message1')
;TI"
wait
;TI"$puts "Still received only one"
;TI"r.send('message2')
;TI"r.take
;T;
0o;
; [I"Output:;T@o;; [
I"Before first receive
;TI"Still not received
;TI"Received: message1
;TI"Still received only one
;TI"Received: message2
;T;
0o;
; [I"WIf close_incoming was called on the ractor, the method raises Ractor::ClosedError ;TI"5if there are no more messages in incoming queue:;T@o;; [I"Ractor.new do
;TI" close_incoming
;TI" receive
;TI" end
;TI"
wait
;TI"p# in `receive': The incoming port is already closed => #<Ractor:#2 test.rb:1 running> (Ractor::ClosedError);T;
0:
@fileI"ractor.rb;T:0@omit_headings_from_table_of_contents_below0I"Ractor.receive -> msg
;T0[[I" recv;To;; [ ;@N;0I"();T@NFI"Ractor;TcRDoc::NormalClass00