Skip to content
instance method · added in Ruby 4.0

Ractor#monitor

[T < ::Symbol] (::Ractor::Port[T]) -> untyped
ractor.monitor(port) → self

Registers the port as a monitoring port for this ractor. When the ractor terminates, the port receives a Symbol object.

  • :exited is sent if the ractor terminates without an unhandled exception.

  • :aborted is sent if the ractor terminates by an unhandled exception.

    Example
    r = Ractor.new{ some_task() }
    r.monitor(port = Ractor::Port.new)
    port.receive #=> :exited and r is terminated
    
    r = Ractor.new{ raise "foo" }
    r.monitor(port = Ractor::Port.new)
    port.receive #=> :aborted and r is terminated by the RuntimeError "foo"
    

Ruby version changes

  1. 4.0
See also #join #name #inspect #receive also in 4.1