Class: Farce::Local::Flag
- Inherits:
-
Object
- Object
- Farce::Local::Flag
- Includes:
- Abstract::Flag, Shareable::Tracked
- Defined in:
- lib/farce/local/flag.rb
Overview
A shareable atomic boolean with an independent value in each scope. Only true and false are accepted. Read #value to test its state.
Instance Attribute Summary
Attributes included from Scoped
Instance Method Summary collapse
-
#compare_and_set(expected, replacement) ⇒ Boolean
Replace the value atomically if it matches the expected boolean.
-
#initialize(value = false, scope: :ractor) ⇒ BasicObject
constructor
Valid scopes are: *
:ractor- The value is shared by all threads within the same Ractor. -
#set ⇒ true
Set the flag to true.
-
#store(value) ⇒ Boolean
(also: #value=)
Store a boolean value.
-
#swap(value) ⇒ Boolean
Replace the value and return its previous state.
-
#toggle ⇒ Boolean
Atomically invert the value.
-
#unset ⇒ false
Set the flag to false.
-
#value ⇒ Boolean
(also: #get)
The current value.
Methods included from Shareable
Methods included from Internal::ValueSerialization
#as_extended_json, #as_json, #to_bson, #to_bson_normalized_value, #to_cbor, #to_json, #to_msgpack
Methods included from Abstract::Value
Methods included from Internal::Copyable
Constructor Details
#initialize(value = false, scope: :ractor) ⇒ BasicObject
Valid scopes are:
:ractor- The value is shared by all threads within the same Ractor.:thread_group- The value is shared by all threads within the same thread group.:thread- The value is shared by all fibers within the same thread.:fiber_storage- The value is shared by all fibers using the same storage. Unless explicitly specified, storage is inherited from the parent fiber for blocking fibers, but not for non-blocking fibers (such as those created by Scheduler#schedule).:fiber- Each fiber has its own independent value.
|
|
# File 'lib/farce/local/flag.rb', line 14
|
Instance Method Details
#compare_and_set(expected, replacement) ⇒ Boolean
Replace the value atomically if it matches the expected boolean.
49 |
# File 'lib/farce/local/flag.rb', line 49 def compare_and_set(expected, replacement) = scoped_value.compare_and_set(expected, replacement) |
#set ⇒ true
Set the flag to true.
27 |
# File 'lib/farce/local/flag.rb', line 27 def set = scoped_value.set |
#store(value) ⇒ Boolean Also known as: value=
Store a boolean value.
36 |
# File 'lib/farce/local/flag.rb', line 36 def store(value) = scoped_value.store(value) |
#swap(value) ⇒ Boolean
Replace the value and return its previous state.
43 |
# File 'lib/farce/local/flag.rb', line 43 def swap(value) = scoped_value.swap(value) |
#toggle ⇒ Boolean
Atomically invert the value.
53 |
# File 'lib/farce/local/flag.rb', line 53 def toggle = scoped_value.toggle |
#unset ⇒ false
Set the flag to false.
31 |
# File 'lib/farce/local/flag.rb', line 31 def unset = scoped_value.unset |
#value ⇒ Boolean Also known as: get
Returns the current value.
21 |
# File 'lib/farce/local/flag.rb', line 21 def value = scoped_value.value |