HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/share/ri/3.0.0/system/Ractor/receive_if-c.ri
U:RDoc::AnyMethod[iI"receive_if:ETI"Ractor::receive_if;TT:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph;	[I"%Receive only a specific message.;To:RDoc::Markup::BlankLineo;
;	[I"HInstead of Ractor.receive, Ractor.receive_if can provide a pattern ;TI"9by a block and you can choose the receiving message.;T@o:RDoc::Markup::Verbatim;	[I"r = Ractor.new do
;TI"?  p Ractor.receive_if{|msg| msg.match?(/foo/)} #=> "foo3"
;TI"?  p Ractor.receive_if{|msg| msg.match?(/bar/)} #=> "bar1"
;TI"?  p Ractor.receive_if{|msg| msg.match?(/baz/)} #=> "baz2"
;TI"	end
;TI"r << "bar1"
;TI"r << "baz2"
;TI"r << "foo3"
;TI"r.take
;T:@format0o;
;	[I"This will output:;T@o;;	[I"
foo3
;TI"
bar1
;TI"
baz2
;T;
0o;
;	[	I"^If the block returns a truthy value, the message will be removed from the incoming queue ;TI"and returned. ;TI"VOtherwise, the messsage remains in the incoming queue and the following received ;TI"-messages are checked by the given block.;T@o;
;	[I"JIf there are no messages left in the incoming queue, the method will ;TI"%block until new messages arrive.;T@o;
;	[I"ZIf the block is escaped by break/return/exception/throw, the message is removed from ;TI"?the incoming queue as if a truthy value had been returned.;T@o;;	[I"r = Ractor.new do
;TI"7  val = Ractor.receive_if{|msg| msg.is_a?(Array)}
;TI",  puts "Received successfully: #{val}"
;TI"	end
;TI"
;TI"r.send(1)
;TI"r.send('test')
;TI"
wait
;TI"2puts "2 non-matching sent, nothing received"
;TI"r.send([1, 2, 3])
;TI"
wait
;T;
0o;
;	[I"Prints:;T@o;;	[I"+2 non-matching sent, nothing received
;TI"&Received successfully: [1, 2, 3]
;T;
0o;
;	[I"SNote that you can not call receive/receive_if in the given block recursively. ;TI"<It means that you should not do any tasks in the block.;T@o;;	[I"Ractor.current << true
;TI"-Ractor.receive_if{|msg| Ractor.receive}
;TI"O#=> `receive': can not call receive/receive_if recursively (Ractor::Error);T;
0:
@fileI"ractor.rb;T:0@omit_headings_from_table_of_contents_below0I"-Ractor.receive_if {|msg| block } -> msg
;T0[I"	(&b);T@QFI"Ractor;TcRDoc::NormalClass00