Class: Farce::Abstract::Atom Abstract
- Inherits:
-
Object
- Object
- Farce::Abstract::Atom
- Includes:
- Value, Internal::Copyable, Internal::ValueSerialization, Internal::Inspect, Internal::MarshalSupport::Atom
- Defined in:
- lib/farce/abstract/atom.rb,
lib/farce/integrations/psych.rb,
lib/farce/integrations/active_support/blank.rb
Overview
Common interface and behavior for atomic references.
Concrete implementations decide how values are retained and transferred.
A value may become nil without an explicit update when an implementation
retains it weakly.
Direct Known Subclasses
WeakAtom, Farce::Atom, Local::Atom, Strict::Atom, Transaction::Atom, Unshared::Atom
ActiveSupport Integration collapse
-
#blank? ⇒ Boolean
True if the atom's value is blank, false otherwise.
Methods included from Internal::ValueSerialization
Methods included from Internal::Copyable
Instance Method Summary collapse
-
#compare_and_set(expected, new_value, timeout: nil) ⇒ Boolean
Atomically replace the current value if it matches the expected value.
-
#compare_by_identity? ⇒ Boolean
Whether comparisons use object identity instead of equality.
-
#get(timeout: nil) { ... } ⇒ BasicObject?
Return the current value, waiting for any update in progress.
-
#store(new_value, timeout: nil) { ... } ⇒ BasicObject?
Store a new value, waiting for any update in progress.
-
#store_if_absent(timeout: nil) { ... } ⇒ BasicObject?
Compute and store a value if the current value is nil.
-
#swap(new_value, timeout: nil) { ... } ⇒ BasicObject?
Replace the current value and return the previous value.
-
#update(timeout: nil) {|current| ... } ⇒ BasicObject?
Atomically replace the current value with the result of a block.
-
#upsert(initial_value, timeout: nil) {|current| ... } ⇒ BasicObject?
Store an initial value if the current value is nil, otherwise replace it with the result of a block.
-
#value ⇒ BasicObject?
Return the current value without waiting for an update in progress.
-
#value=(new_value) ⇒ BasicObject?
Store a new value.
-
#wait_until(timeout: nil) {|value| ... } ⇒ BasicObject?
Wait until a block condition matches the current value.
-
#wait_until_changed(expected, timeout: nil) { ... } ⇒ BasicObject?
Wait until the current value no longer matches an expected value.
-
#wait_until_match(object, timeout: nil) ⇒ BasicObject?
Wait until
object === valueis true. -
#wait_until_non_nil(timeout: nil) { ... } ⇒ BasicObject?
Wait until the current value is not nil.
-
#wait_until_value(object, timeout: nil) ⇒ BasicObject?
Wait until the current value equals an object using the configured comparison mode.
-
#wait_while(timeout: nil) {|value| ... } ⇒ BasicObject?
Wait while the block returns a truthy value.
-
#wait_while_match(object, timeout: nil) ⇒ BasicObject?
Wait while
object === valueis true. -
#wait_while_value { ... } ⇒ BasicObject?
Wait until the current value no longer matches an expected value.
Methods included from Internal::ValueSerialization
#as_extended_json, #to_bson, #to_bson_normalized_value, #to_cbor, #to_json
Methods included from Value
Instance Method Details
#blank? ⇒ Boolean
This methods is only available if ActiveSupport has been loaded.
Returns true if the atom's value is blank, false otherwise.
34 |
# File 'lib/farce/integrations/active_support/blank.rb', line 34 def blank? = internal_atom.value.blank? |
#compare_and_set(expected, new_value, timeout: nil) ⇒ Boolean
Atomically replace the current value if it matches the expected value.
69 70 71 |
# File 'lib/farce/abstract/atom.rb', line 69 def compare_and_set(expected, new_value, timeout: nil) internal_atom.compare_and_set(expected, new_value, timeout:) end |
#compare_by_identity? ⇒ Boolean
Whether comparisons use object identity instead of equality.
24 |
# File 'lib/farce/abstract/atom.rb', line 24 def compare_by_identity? = internal_atom.compare_by_identity? |
#get(timeout: nil) { ... } ⇒ BasicObject?
Return the current value, waiting for any update in progress.
41 |
# File 'lib/farce/abstract/atom.rb', line 41 def get(timeout: nil, &) = internal_atom.get(timeout:, &) |
#store(new_value, timeout: nil) { ... } ⇒ BasicObject?
Store a new value, waiting for any update in progress.
48 |
# File 'lib/farce/abstract/atom.rb', line 48 def store(new_value, timeout: nil, &) = internal_atom.store(new_value, timeout:, &) |
#store_if_absent(timeout: nil) { ... } ⇒ BasicObject?
Compute and store a value if the current value is nil.
62 |
# File 'lib/farce/abstract/atom.rb', line 62 def store_if_absent(timeout: nil, &) = internal_atom.store_if_absent(timeout:, &) |
#swap(new_value, timeout: nil) { ... } ⇒ BasicObject?
Replace the current value and return the previous value.
55 |
# File 'lib/farce/abstract/atom.rb', line 55 def swap(new_value, timeout: nil, &) = internal_atom.swap(new_value, timeout:, &) |
#update(timeout: nil) {|current| ... } ⇒ BasicObject?
Atomically replace the current value with the result of a block.
79 |
# File 'lib/farce/abstract/atom.rb', line 79 def update(timeout: nil, &) = internal_atom.update(timeout:, &) |
#upsert(initial_value, timeout: nil) {|current| ... } ⇒ BasicObject?
Store an initial value if the current value is nil, otherwise replace it with the result of a block.
88 |
# File 'lib/farce/abstract/atom.rb', line 88 def upsert(initial_value, timeout: nil, &) = internal_atom.upsert(initial_value, timeout:, &) |
#value ⇒ BasicObject?
Return the current value without waiting for an update in progress.
28 |
# File 'lib/farce/abstract/atom.rb', line 28 def value = internal_atom.value |
#value=(new_value) ⇒ BasicObject?
Store a new value.
33 34 35 |
# File 'lib/farce/abstract/atom.rb', line 33 def value=(new_value) store(new_value) end |
#wait_until(timeout: nil) {|value| ... } ⇒ BasicObject?
Wait until a block condition matches the current value. One timeout budget covers all checks and waits. The block is not interrupted.
97 |
# File 'lib/farce/abstract/atom.rb', line 97 def wait_until(timeout: nil, &) = Internal.wait_until(self, timeout:, &) |
#wait_until_changed(expected, timeout: nil) { ... } ⇒ BasicObject?
Wait until the current value no longer matches an expected value.
142 143 144 |
# File 'lib/farce/abstract/atom.rb', line 142 def wait_until_changed(expected, timeout: nil, &) internal_atom.wait_until_changed(expected, timeout:, &) end |
#wait_until_match(object, timeout: nil) ⇒ BasicObject?
Wait until object === value is true.
133 134 135 |
# File 'lib/farce/abstract/atom.rb', line 133 def wait_until_match(object, timeout: nil) wait_until(timeout:) { |value| object === value } # rubocop:disable Style/CaseEquality end |
#wait_until_non_nil(timeout: nil) { ... } ⇒ BasicObject?
Wait until the current value is not nil.
150 |
# File 'lib/farce/abstract/atom.rb', line 150 def wait_until_non_nil(timeout: nil, &) = internal_atom.wait_until_non_nil(timeout:, &) |
#wait_until_value(object, timeout: nil) ⇒ BasicObject?
Wait until the current value equals an object using the configured comparison mode.
125 126 127 |
# File 'lib/farce/abstract/atom.rb', line 125 def wait_until_value(object, timeout: nil) wait_until(timeout:) { |value| compare_by_identity? ? object.equal?(value) : object == value } end |
#wait_while(timeout: nil) {|value| ... } ⇒ BasicObject?
Wait while the block returns a truthy value.
105 106 107 108 |
# File 'lib/farce/abstract/atom.rb', line 105 def wait_while(timeout: nil) raise LocalJumpError, "no block given" unless block_given? wait_until(timeout:) { |value| !yield(value) } end |
#wait_while_match(object, timeout: nil) ⇒ BasicObject?
Wait while object === value is true.
114 115 116 |
# File 'lib/farce/abstract/atom.rb', line 114 def wait_while_match(object, timeout: nil) wait_while(timeout:) { |value| object === value } # rubocop:disable Style/CaseEquality end |
#wait_while_value { ... } ⇒ BasicObject?
Wait until the current value no longer matches an expected value.
119 |
# File 'lib/farce/abstract/atom.rb', line 119 def wait_while_value(...) = wait_until_changed(...) |