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.
202 203 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 235 236 237 238 239 240 241 |
# File 'lib/farce/envelope.rb', line 202 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.
226 |
# File 'lib/farce/envelope.rb', line 226 def claim = owned? ? self : nil |
#claimed? ⇒ Boolean
Returns true if the envelope has been claimed by any Ractor, false otherwise.
229 |
# File 'lib/farce/envelope.rb', line 229 def claimed? = true |