Class: Farce::Envelope::Move
- Inherits:
-
Farce::Envelope
- Object
- Farce::Envelope
- Farce::Envelope::Move
- Includes:
- Shareable::Unfreezable, Internal::MarshalSupport::Reject
- Defined in:
- lib/farce/envelope.rb
Overview
An envelope that moves its contents. Can only be opened by a single Ractor. The value will be moved once when the envelope is created, and then once when the envelope is opened.
Constant Summary
Constants inherited from Farce::Envelope
Class Method Summary collapse
-
.new(value) ⇒ Move, 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) ⇒ Move
constructor
A new instance of Move.
-
#owned? ⇒ Boolean
trueif the envelope has been claimed by the current Ractor,falseotherwise.
Methods included from Shareable
Methods inherited from Farce::Envelope
#blank?, #claim!, #same_value?, #value
Methods included from Abstract::Value
Methods included from Internal::Noncopyable
Constructor Details
#initialize(value) ⇒ Move
Returns a new instance of Move.
173 174 175 176 177 178 |
# File 'lib/farce/envelope.rb', line 173 def initialize(value, auto_unwrap = nil) @vault = VAULT_ATOM.store_if_absent { Internal::Vault.new } @owner = Internal::Atom.new super @vault.move_in(self, value) end |
Class Method Details
.new(value) ⇒ Move, Share
Returns A new envelope wrapping the given value.
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 |
# File 'lib/farce/envelope.rb', line 167 class Move < Farce::Envelope include Internal::MarshalSupport::Reject include Shareable::Unfreezable # @overload initialize(value) # @param [Object] value The value to wrap in the envelope. def initialize(value, auto_unwrap = nil) @vault = VAULT_ATOM.store_if_absent { Internal::Vault.new } @owner = Internal::Atom.new super @vault.move_in(self, value) end # (see Envelope#claim) def claim owner = @owner.store_if_absent { Ractor.current } self if owner == Ractor.current end # (see Envelope#claimed?) def claimed? = !@owner.value.nil? # (see Envelope#owned?) def owned? = @owner.value == Ractor.current private def retrieve = @vault.move_out(self) end |
Instance Method Details
#claim ⇒ Envelope?
Attempts to claim the envelope for the current Ractor.
181 182 183 184 |
# File 'lib/farce/envelope.rb', line 181 def claim owner = @owner.store_if_absent { Ractor.current } self if owner == Ractor.current end |
#claimed? ⇒ Boolean
Returns true if the envelope has been claimed by any Ractor, false otherwise.
187 |
# File 'lib/farce/envelope.rb', line 187 def claimed? = !@owner.value.nil? |