Class: Farce::Envelope::Share
- Inherits:
-
Farce::Envelope
- Object
- Farce::Envelope
- Farce::Envelope::Share
- Defined in:
- lib/farce/envelope.rb
Overview
An envelope that wraps a Ractor-shareable value. Can be opened by any Ractor. Defeats the purpose of an envelope, but is provided for code that expects an envelope.
Constant Summary
Constants inherited from Farce::Envelope
Instance Attribute Summary collapse
-
#value ⇒ BasicObject
readonly
Returns the value of attribute value.
Class Method Summary collapse
-
.new(value) ⇒ Share
A new envelope wrapping the given value.
Instance Method Summary collapse
-
#claim ⇒ Envelope?
Attempts to claim the envelope for the current Ractor.
-
#claimed? ⇒ Boolean
trueif the envelope has been claimed by any Ractor,falseotherwise. -
#initialize(value) ⇒ Share
constructor
A new instance of Share.
-
#owned? ⇒ Boolean
trueif the envelope has been claimed by the current Ractor,falseotherwise.
Methods included from Internal::Copyable
Methods inherited from Farce::Envelope
#blank?, #claim!, #same_value?
Methods included from Abstract::Value
Methods included from Shareable
Methods included from Internal::Noncopyable
Constructor Details
#initialize(value) ⇒ Share
Returns a new instance of Share.
257 258 259 260 261 |
# File 'lib/farce/envelope.rb', line 257 def initialize(value, auto_unwrap = nil) raise ArgumentError, "value must be shareable" unless Ractor.shareable?(value) @value = value super end |
Instance Attribute Details
#value ⇒ BasicObject (readonly)
Returns the value of attribute value.
253 254 255 |
# File 'lib/farce/envelope.rb', line 253 def value @value end |
Class Method Details
.new(value) ⇒ Share
Returns A new envelope wrapping the given value.
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 |
# File 'lib/farce/envelope.rb', line 250 class Share < Farce::Envelope include Copyable attr_reader :value # @overload initialize(value) # @param value [Object] The value to wrap in the envelope. Must be shareable. def initialize(value, auto_unwrap = nil) raise ArgumentError, "value must be shareable" unless Ractor.shareable?(value) @value = value super end # @api private def marshal_dump = [1, value, auto_unwrap] # @api private def marshal_load(data) value, manager = Internal::MarshalSupport.payload(data, 2) initialize(Ractor.make_shareable(value), manager) end # (see Envelope#claim) def claim = self # (see Envelope#claimed?) def claimed? = true # (see Envelope#owned?) def owned? = true end |
Instance Method Details
#claim ⇒ Envelope?
Attempts to claim the envelope for the current Ractor.
273 |
# File 'lib/farce/envelope.rb', line 273 def claim = self |
#claimed? ⇒ Boolean
Returns true if the envelope has been claimed by any Ractor, false otherwise.
276 |
# File 'lib/farce/envelope.rb', line 276 def claimed? = true |
#owned? ⇒ Boolean
Returns true if the envelope has been claimed by the current Ractor, false otherwise.
279 |
# File 'lib/farce/envelope.rb', line 279 def owned? = true |