D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
proc
/
self
/
root
/
opt
/
alt
/
ruby34
/
share
/
ri
/
system
/
Ractor
/
Filename :
receive-c.ri
back
Copy
U:RDoc::AnyMethod[iI"receive:ETI"Ractor::receive;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"OReceive a message from the incoming port of the current ractor (which was ;TI".sent there by #send from another ractor).;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"FAlternatively, the 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")# This prints: "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"9if there are no more messages in the 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