Usage¶
-
class
atomic.
Atomic
(value=None)¶ An atomic class that guarantees atomic updates to its contained value.
-
compare_and_set
(expect_value, new_value)¶ Atomically sets the value to the given value if the current value is equal to the expected value.
Parameters: - expect_value – the expected value
- new_value – the new value
-
get_and_set
(new_value)¶ Atomically sets to the given value and returns the old value
Parameters: new_value – the new value
-
try_update
(update_func)¶ Update value based on the given function.
If the value changes before the update can happen, it will raise a
ConcurrentUpdateException
.Parameters: update_func (func) – a function that given the current value return the new value Raises: ConcurrentUpdateException
-
update
(update_func)¶ Update value based on the given function.
It may run the block repeatedly if there are other concurrent updates in progress.
Parameters: update_func (func) – a function that given the current value return the new value
-
value
¶ Get and set current value
-