⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
Ractor
/
Edit File: take-i.ri
U:RDoc::AnyMethod[iI" take:ETI"Ractor#take;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"dTake a message from ractor's outgoing port, which was put there by Ractor.yield or at ractor's ;TI"finalization.;To:RDoc::Markup::BlankLine o:RDoc::Markup::Verbatim; [I"r = Ractor.new do ;TI"% Ractor.yield 'explicit yield' ;TI" 'last value' ;TI" end ;TI"&puts r.take #=> 'explicit yield' ;TI""puts r.take #=> 'last value' ;TI"Mputs r.take # Ractor::ClosedError (The outgoing-port is already closed) ;T:@format0o; ; [I"]The fact that the last value is also put to outgoing port means that +take+ can be used ;TI"[as some analog of Thread#join ("just wait till ractor finishes"), but don't forget it ;TI"Qwill raise if somebody had already consumed everything ractor have produced.;T@o; ; [I"eIf the outgoing port was closed with #close_outgoing, the method will raise Ractor::ClosedError.;T@o;; [ I"r = Ractor.new do ;TI" sleep(500) ;TI"( Ractor.yield 'Hello from ractor' ;TI" end ;TI"r.close_outgoing ;TI"r.take ;TI"A# Ractor::ClosedError (The outgoing-port is already closed) ;TI"R# The error would be raised immediately, not when ractor will try to receive ;T; 0o; ; [I"UIf an uncaught exception is raised in the Ractor, it is propagated on take as a ;TI"Ractor::RemoteError.;T@o;; [I"7r = Ractor.new {raise "Something weird happened"} ;TI" ;TI"begin ;TI" r.take ;TI"rescue => e ;TI"O p e # => #<Ractor::RemoteError: thrown by remote Ractor.> ;TI"" p e.ractor == r # => true ;TI"G p e.cause # => #<RuntimeError: Something weird happened> ;TI" end ;T; 0o; ; [I"cRactor::ClosedError is a descendant of StopIteration, so the closing of the ractor will break ;TI"-the loops without propagating the error:;T@o;; [I"r = Ractor.new do ;TI"1 3.times {|i| Ractor.yield "message #{i}"} ;TI" "finishing" ;TI" end ;TI" ;TI"'loop {puts "Received: " + r.take} ;TI""puts "Continue successfully" ;T; 0o; ; [I"This will print:;T@o;; [ I"Received: message 0 ;TI"Received: message 1 ;TI"Received: message 2 ;TI"Received: finishing ;TI"Continue successfully;T; 0: @fileI"ractor.rb;T:0@omit_headings_from_table_of_contents_below0I"ractor.take -> msg ;T0[ I"();T@QFI"Ractor;TcRDoc::NormalClass00
Simpan