Class: Farce::Envelope::Local
- Inherits:
-
Farce::Envelope
- Object
- Farce::Envelope
- Farce::Envelope::Local
- Defined in:
- lib/farce/envelope.rb
Overview
An envelope that keeps its contents local to the Ractor that created it. Can only be opened by the Ractor that created it.
Constant Summary
Constants inherited from Farce::Envelope
Class Method Summary collapse
-
.new(value) ⇒ Local, 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) ⇒ Local
constructor
A new instance of Local.
-
#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?, #value
Methods included from Abstract::Value
Methods included from Shareable
Methods included from Internal::Noncopyable
Constructor Details
Class Method Details
.new(value) ⇒ Local, Share
Returns A new envelope wrapping the given value.
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/farce/envelope.rb', line 156 class Local < Farce::Envelope include Copyable # @overload initialize(value) # @param value [Object] The value to wrap in the envelope. def initialize(value, auto_unwrap = nil) @owner = Ractor.current Internal::Storage.ractor[self] = value super end # @api private def marshal_dump raise TypeError, "local envelope belongs to another Ractor" unless owned? [1, Internal::Storage.ractor[self], auto_unwrap] end # @api private def marshal_load(data) value, manager = Internal::MarshalSupport.payload(data, 2) initialize(value, manager) end # (see Envelope#claim) def claim = owned? ? self : nil # (see Envelope#claimed?) def claimed? = true # (see Envelope#owned?) def owned? = @owner == Ractor.current private def initialize_copy(other) super other.claim! Internal::Storage.ractor[self] = other.value.dup end end |
Instance Method Details
#claim ⇒ Envelope?
Attempts to claim the envelope for the current Ractor.
180 |
# File 'lib/farce/envelope.rb', line 180 def claim = owned? ? self : nil |
#claimed? ⇒ Boolean
Returns true if the envelope has been claimed by any Ractor, false otherwise.
183 |
# File 'lib/farce/envelope.rb', line 183 def claimed? = true |