HEX
Server: Apache
System: Linux s198.coreserver.jp 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC 2025 x86_64
User: nagasaki (10062)
PHP: 7.1.33
Disabled: NONE
Upload Files
File: //usr/local/rvm/gems/ruby-2.5.9/doc/concurrent-ruby-1.1.9/ri/Concurrent/Atom/cdesc-Atom.ri
U:RDoc::NormalClass[iI"	Atom:ETI"Concurrent::Atom;TI"Synchronization::Object;To:RDoc::Markup::Document:@parts[o;;["o:RDoc::Markup::Paragraph;[I"JAtoms provide a way to manage shared, synchronous, independent state.;To:RDoc::Markup::BlankLineo;	;[
I"MAn atom is initialized with an initial value and an optional validation ;TI"Mproc. At any time the value of the atom can be synchronously and safely ;TI"Ichanged. If a validator is given at construction then any new value ;TI"Gwill be checked against the validator and will be rejected if the ;TI"4validator returns false or raises an exception.;T@o;	;[
I"OThere are two ways to change the value of an atom: {#compare_and_set} and ;TI"P{#swap}. The former will set the new value if and only if it validates and ;TI"Qthe current value matches the new value. The latter will atomically set the ;TI"Lnew value to the result of running the given block if and only if that ;TI"value validates.;T@o;	;[I"## Example;T@o;	;[I"	``` ;TI""def next_fibonacci(set = nil);To:RDoc::Markup::Verbatim;[I"return [0, 1] if set.nil?
;TI"2set + [set[-2..-1].reduce{|sum,x| sum + x }]
;T:@format0o;	;[I"end;T@o;	;[I",# create an atom with an initial value ;TI"0atom = Concurrent::Atom.new(next_fibonacci);T@o;	;[I""# send a few update requests ;TI"5.times do;To;;[I"+atom.swap{|set| next_fibonacci(set) }
;T;0o;	;[I"end;T@o;	;[I"# get the current value ;TI"*atom.value #=> [0, 1, 1, 2, 3, 5, 8] ;TI"```;T@o;	;[I"## Observation;T@o;	;[I"PAtoms support observers through the {Concurrent::Observable} mixin module. ;TI"PNotification of observers occurs every time the value of the Atom changes. ;TI"SWhen notified the observer will receive three arguments: `time`, `old_value`, ;TI"Pand `new_value`. The `time` argument is the time at which the value change ;TI"Noccurred. The `old_value` is the value of the Atom when the change began ;TI"LThe `new_value` is the value to which the Atom was set when the change ;TI"Ocompleted. Note that `old_value` and `new_value` may be the same. This is ;TI"Onot an error. It simply means that the change operation returned the same ;TI"value.;T@o;	;[I"UUnlike in Clojure, `Atom` cannot participate in {Concurrent::TVar} transactions.;T@o;	;[I",@!macro thread_safe_variable_comparison;T@o;	;[I"1@see http://clojure.org/atoms Clojure Atoms ;TI"_@see http://clojure.org/state Values and Change - Clojure's approach to Identity and State;T:
@fileI"+lib/concurrent-ruby/concurrent/atom.rb;T:0@omit_headings_from_table_of_contents_below0;
0;0[[[[I"Concern::Observable;To;;[;
@Y;0I"+lib/concurrent-ruby/concurrent/atom.rb;T[[I"
class;T[[:public[[I"new;T@a[:protected[[:private[[I"
instance;T[[;[[I"compare_and_set;T@a[I"
reset;T@a[I"	swap;T@a[;[[;[[I"valid?;T@a[[U:RDoc::Context::Section[i0o;;[;
0;0[@YI"Concurrent;TcRDoc::NormalModule