Skip to content

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

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
See also #<< #closed? .new #inspect also in 4.0