Spec-Zone.ru › Ruby 3.3

класс Ractor::ClosedError

Родитель:
rb_eStopIteration

Вызывается, когда попытка отправить сообщение закрытому порту или получить сообщение из закрытого и пустого порта. Порты могут быть закрыты явно с помощью Ractor#close_outgoing/close_incoming и неявно закрываются, когда Ractor завершается.

r = Ractor.new { sleep(500) }
r.close_outgoing
r.take # Ractor::ClosedError

ClosedError — потомок StopIteration, поэтому закрытие рактора прервет циклы без распространения ошибки:

r = Ractor.new do
  loop do
    msg = receive # raises ClosedError and loop traps it
    puts "Received: #{msg}"
  end
  puts "loop exited"
end

3.times{|i| r << i}
r.close_incoming
r.take
puts "Continue successfully"

Это выведет:

Received: 0
Received: 1
Received: 2
loop exited
Continue successfully

Ruby Core © 1993–2022 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API