@@ -24,23 +24,27 @@ module Concurrent
24
24
class Atom < Synchronization ::Object
25
25
include Dereferenceable
26
26
27
- # @!macro [attach] atom_initialize
27
+ # Create a new atom with the given initial value.
28
28
#
29
- # Create a new atom with the given initial value.
29
+ # @param [Object] value The initial value
30
+ # @param [Hash] opts The options used to configure the atom
31
+ # @option opts [Proc] :validator (nil) Optional proc used to validate new
32
+ # values. It must accept one and only one argument which will be the
33
+ # intended new value. The validator will return true if the new value
34
+ # is acceptable else return false (preferrably) or raise an exception.
30
35
#
31
- # @param [Object] value The initial value
32
- # @param [Hash] opts The options used to configure the atom
33
- # @option opts [Proc] :validator (nil) Optional proc used to validate new
34
- # values. It must accept one and only one argument which will be the
35
- # intended new value. The validator will return true if the new value
36
- # is acceptable else return false (preferrably) or raise an exception.
37
- #
38
- # @!macro deref_options
36
+ # @!macro deref_options
39
37
#
40
- # @raise [ArgumentError] if the validator is not a `Proc` (when given)
38
+ # @raise [ArgumentError] if the validator is not a `Proc` (when given)
41
39
def initialize ( value , opts = { } )
42
40
super ( )
43
- synchronize { ns_initialize ( value , opts ) }
41
+
42
+ @validator = opts . fetch ( :validator , -> ( v ) { true } )
43
+ raise ArgumentError . new ( 'validator must be a proc' ) unless @validator . is_a? Proc
44
+
45
+ @value = Concurrent ::AtomicReference . new ( value )
46
+ ns_set_deref_options ( opts )
47
+ ensure_ivar_visibility!
44
48
end
45
49
46
50
# The current value of the atom.
@@ -113,15 +117,6 @@ def compare_and_set(old_value, new_value)
113
117
114
118
private
115
119
116
- # @!macro atom_initialize
117
- # @!visibility private
118
- def ns_initialize ( value , opts )
119
- @validator = opts . fetch ( :validator , -> ( v ) { true } )
120
- raise ArgumentError . new ( 'validator must be a proc' ) unless @validator . is_a? Proc
121
- @value = Concurrent ::AtomicReference . new ( value )
122
- ns_set_deref_options ( opts )
123
- end
124
-
125
120
# @!macro atom_compare_and_set
126
121
# @raise [Exception] if the validator proc raises an exception
127
122
# @!visibility private
0 commit comments