Module: Farce::Ractor
- Includes:
- Internal::MarshalSupport::Reject
- Defined in:
- lib/farce/ractor.rb,
lib/farce/_yard/ractor.rb
Overview
Entry point for Ractor support.
This is always a module, but if native Ractor support is available:
- It gets mixed into Ractor. This has no effect beyond another entry in the inheritance chain,
so
is_a?(Farce::Ractor)andFarce::Ractor === ractorwork as expected. - It delegates, wraps, or backports known Ractor class methods.
If not, then this module provides a polyfill for Ractors. With the following caveats:
- It uses thread groups to keep track of Thread-to-Ractor associations.
- All objects are considered shareable.
- It does not monkey-patch
Thread. This means in particular:Thread.listwill include all threads from all Ractors. Use Farce::Ractor.threads instead.Thread.mainwill return the main thread of the main Ractor, even if called from a different Ractor. Use Farce::Ractor.main_thread instead.
Defined Under Namespace
Classes: Port
Constant Summary collapse
- Error =
Either
Ractor::Erroror a subclass ofRuntimeErrorif native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError)
- ClosedError =
Either
Ractor::ClosedErroror a subclass ofStopIterationif native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration)
- IsolationError =
Either
Ractor::IsolationErroror a subclass of Error if native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error)
- MovedError =
Either
Ractor::MovedErroror a subclass of Error if native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error)
- RemoteError =
Either
Ractor::RemoteErroror a subclass of Error if native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error)
- UnsafeError =
Either
Ractor::UnsafeErroror a subclass of Error if native Ractors are not available. Will pick up an error class defined by a shim/polyfill if one is loaded, like ractor-shim. defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error)
- MovedObject =
Either
Ractor::MovedObjector a subclass ofBasicObjectif native Ractors are not available. Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" }
Class Method Summary collapse
-
.[](key) ⇒ BasicObject?
Retrieves a value from the current Ractor's storage by key.
-
.[]=(key, value) ⇒ BasicObject
Stores a value in the current Ractor's storage by key.
-
.builtin? ⇒ Boolean
trueif native Ractors are available,falseotherwise. -
.count ⇒ Integer
Returns the number of Ractors.
-
.current ⇒ Ractor
Returns the current Ractor instance.
-
.main ⇒ Ractor
Returns the main Ractor instance.
-
.main? ⇒ Boolean
Checks if the current Ractor is the main Ractor.
-
.main_thread ⇒ Thread
Returns the main thread of the current Ractor.
-
.make_shareable(object, copy: false) ⇒ BasicObject
Makes an object shareable between Ractors.
-
.new(*args, name: nil) {|*args| ... } ⇒ Ractor
Creates a new Ractor instance.
-
.receive(timeout: nil) ⇒ BasicObject?
(also: recv)
Receives a message on the current Ractor's default port.
-
.select(*ractors_or_ports, timeout: nil) ⇒ Array(Object, BasicObject)?
Blocks the current Thread until one of the given Ractors or Ports produces a value, or until the timeout has been reached.
-
.shareable?(object) ⇒ Boolean
Checks if an object is shareable between Ractors.
-
.shareable_lambda(self: nil) { ... } ⇒ Proc
Binds a lambda to the given
selfand makes it shareable between Ractors. -
.shareable_proc(self: nil) { ... } ⇒ Proc
Binds a proc to the given
selfand makes it shareable between Ractors. -
.shim? ⇒ Boolean
falseif native Ractors are available,trueotherwise. -
.store_if_absent(key) { ... } ⇒ BasicObject
Stores a value in the current Ractor's storage by key if it is not already present.
-
.threads ⇒ Array<Thread>
Returns the list of threads in the current Ractor.
Instance Method Summary collapse
-
#default_port ⇒ Ractor::Port
The default port for the Ractor.
-
#join ⇒ self
Blocks the current Thread until the Ractor has terminated.
-
#main? ⇒ Boolean
trueif the Ractor is the main Ractor. -
#monitor(port) ⇒ Boolean
Monitors the given port for termination of the Ractor.
-
#name ⇒ String?
The name of the Ractor, or
nilif it has no name. -
#receive(timeout: nil) ⇒ BasicObject?
(also: #recv)
Receives a message on the Ractor's default port.
-
#send(message, move: false) ⇒ self
(also: #<<)
Sends a message to the Ractor's default port.
- #take ⇒ BasicObject deprecated Deprecated.
-
#unmonitor(port) ⇒ self
Stops monitoring the given port for termination of the Ractor.
-
#value ⇒ BasicObject
Blocks the current Thread until the Ractor has terminated, and returns the value returned by the Ractor's block.
Class Method Details
.[](key) ⇒ BasicObject?
Retrieves a value from the current Ractor's storage by key.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.[]=(key, value) ⇒ BasicObject
Stores a value in the current Ractor's storage by key.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.builtin? ⇒ Boolean
This method isn't part of the official Ractor API, but is compatible with the ractor-shim gem.
Returns true if native Ractors are available, false otherwise.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.count ⇒ Integer
Returns the number of Ractors.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.current ⇒ Ractor
Returns the current Ractor instance.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.main ⇒ Ractor
Returns the main Ractor instance.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.main? ⇒ Boolean
Checks if the current Ractor is the main Ractor.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.main_thread ⇒ Thread
This method is not part of the official Ractor API, but is a replacement for a Ractor-unaware Thread.main.
Returns the main thread of the current Ractor.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.make_shareable(object, copy: false) ⇒ BasicObject
If native Ractors aren't available, this method simply returns the object, as all objects are shareable.
Makes an object shareable between Ractors.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.new(*args, name: nil) {|*args| ... } ⇒ Ractor
Creates a new Ractor instance.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.receive(timeout: nil) ⇒ BasicObject? Also known as: recv
Receives a message on the current Ractor's default port.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.select(*ractors_or_ports, timeout: nil) ⇒ Array(Object, BasicObject)?
Blocks the current Thread until one of the given Ractors or Ports produces a value, or until the timeout has been reached.
Returns an array containing the Ractor or Port that produced the value, and the value itself.
Or nil if the timeout has been reached.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.shareable?(object) ⇒ Boolean
If native Ractors aren't available, this method always returns true, as all objects are shareable.
Checks if an object is shareable between Ractors.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.shareable_lambda(self: nil) { ... } ⇒ Proc
Binds a lambda to the given self and makes it shareable between Ractors.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.shareable_proc(self: nil) { ... } ⇒ Proc
Binds a proc to the given self and makes it shareable between Ractors.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.shim? ⇒ Boolean
This method isn't part of the official Ractor API, but is compatible with the ractor-shim gem.
Returns false if native Ractors are available, true otherwise.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.store_if_absent(key) { ... } ⇒ BasicObject
Stores a value in the current Ractor's storage by key if it is not already present. This method is thread-safe.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
.threads ⇒ Array<Thread>
This method isn't part of the official Ractor API, but is a replacement for a Ractor-unaware Thread.list.
Returns the list of threads in the current Ractor.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
Instance Method Details
#default_port ⇒ Ractor::Port
Returns The default port for the Ractor.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#join ⇒ self
Blocks the current Thread until the Ractor has terminated.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#main? ⇒ Boolean
Returns true if the Ractor is the main Ractor.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#monitor(port) ⇒ Boolean
Monitors the given port for termination of the Ractor. If the Ractor is already terminated, the port will receive
the Ractor's status immediately. The port will receive wither :exited or :aborted depending on whether the
Ractor terminated normally or with an unhandled exception.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#name ⇒ String?
Returns The name of the Ractor, or nil if it has no name.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#receive(timeout: nil) ⇒ BasicObject? Also known as: recv
Receives a message on the Ractor's default port.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#send(message, move: false) ⇒ self Also known as: <<
Sends a message to the Ractor's default port.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#take ⇒ BasicObject
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#unmonitor(port) ⇒ self
Stops monitoring the given port for termination of the Ractor. If the port was not being monitored, this method has no effect.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |
#value ⇒ BasicObject
Blocks the current Thread until the Ractor has terminated, and returns the value returned by the Ractor's block. Will re-raise any unhandled exception raised in the Ractor's block.
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 |
# File 'lib/farce/ractor.rb', line 217 module Ractor include Internal::MarshalSupport::Reject ::Ractor.include(self) if Internal.native_ractors? # @!parse # # @!scope class # alias recv receive # alias recv receive # alias << send # Either `Ractor::Error` or a subclass of `RuntimeError` if native Ractors are not available. # @!macro RactorError_note # Will pick up an error class defined by a shim/polyfill if one is loaded, # like [ractor-shim](https://github.com/eregon/ractor-shim). Error = defined?(::Ractor::Error) ? ::Ractor::Error : Class.new(RuntimeError) # Either `Ractor::ClosedError` or a subclass of `StopIteration` if native Ractors are not available. # @!macro RactorError_note ClosedError = defined?(::Ractor::ClosedError) ? ::Ractor::ClosedError : Class.new(StopIteration) # Either `Ractor::IsolationError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note IsolationError = defined?(::Ractor::IsolationError) ? ::Ractor::IsolationError : Class.new(Error) # Either `Ractor::MovedError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note MovedError = defined?(::Ractor::MovedError) ? ::Ractor::MovedError : Class.new(Error) # Either `Ractor::RemoteError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note RemoteError = defined?(::Ractor::RemoteError) ? ::Ractor::RemoteError : Class.new(Error) # Either `Ractor::UnsafeError` or a subclass of {Error} if native Ractors are not available. # @!macro RactorError_note UnsafeError = defined?(::Ractor::UnsafeError) ? ::Ractor::UnsafeError : Class.new(Error) # Either `Ractor::MovedObject` or a subclass of `BasicObject` if native Ractors are not available. # Cannot be instantiated directly, but can be used to check if an object has been moved to another Ractor. MovedObject = defined?(::Ractor::MovedObject) ? ::Ractor::MovedObject : Class.new(BasicObject) { def self.new(...) = raise TypeError, "allocator undefined for #{inspect}" } extend Internal::RactorMethods def self.const_missing(name) = name == :Port ? Internal::BasePort : super private_class_method :const_missing # @!visibility private def self.included(base) return if base.const_defined?(:Port, false) base.const_set(:Port, Internal::BasePort) end end |