Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Ractor::Port#close
() -> void
port.close
ractor.rb
View on GitHub ↗
# File tmp/rubies/ruby-4.1.0-preview1/ractor.rb, line 863
def close
__builtin_cexpr! %q{
ractor_port_close(ec, self)
}
end
Closes the port. Sending to a closed port is prohibited. Receiving is also prohibited if there are no messages in its message queue.
Messages already in the queue are kept: a receiver takes them before the port reports itself closed. A Ractor::Port#receive waiting on the port when it closes stops there and raises Ractor::ClosedError, rather than waiting for a message that can no longer arrive.
Only the Ractor which created the port is allowed to close it.
Example
port = Ractor::Port.new Ractor.new port do |port| port.close #=> closing port by other ractors is not allowed (Ractor::Error) end.join