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.
211 212 213 214 215 |
# File 'lib/farce/envelope.rb', line 211 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.
207 208 209 |
# File 'lib/farce/envelope.rb', line 207 def value @value end |
Class Method Details
.new(value) ⇒ Share
Returns A new envelope wrapping the given value.
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/farce/envelope.rb', line 204 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.
227 |
# File 'lib/farce/envelope.rb', line 227 def claim = self |
#claimed? ⇒ Boolean
Returns true if the envelope has been claimed by any Ractor, false otherwise.
230 |
# File 'lib/farce/envelope.rb', line 230 def claimed? = true |
#owned? ⇒ Boolean
Returns true if the envelope has been claimed by the current Ractor, false otherwise.
233 |
# File 'lib/farce/envelope.rb', line 233 def owned? = true |