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.
127 128 129 130 131 132 |
# File 'lib/farce/envelope.rb', line 127 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.
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/farce/envelope.rb', line 121 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.
135 136 137 138 |
# File 'lib/farce/envelope.rb', line 135 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.
141 |
# File 'lib/farce/envelope.rb', line 141 def claimed? = !@owner.value.nil? |