Skip to content

Commit e46a38f

Browse files
expose Concurrent::Synchronization::Volatile module
1 parent 9a80cbb commit e46a38f

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

lib/concurrent/synchronization.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'concurrent/synchronization/jruby_object'
66
require 'concurrent/synchronization/rbx_object'
77
require 'concurrent/synchronization/object'
8+
require 'concurrent/synchronization/volatile'
89

910
require 'concurrent/synchronization/abstract_lockable_object'
1011
require 'concurrent/synchronization/mri_lockable_object'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module Concurrent
2+
module Synchronization
3+
4+
# Volatile adds the attr_volatile class method when included.
5+
#
6+
# @example
7+
# class Foo
8+
# include Concurrent::Synchronization::Volatile
9+
#
10+
# attr_volatile :bar
11+
#
12+
# def initialize
13+
# @volatile_bar = 1
14+
# end
15+
# end
16+
#
17+
# foo = Foo.new
18+
# foo.bar
19+
# => 1
20+
# foo.bar = 2
21+
# => 2
22+
23+
Volatile = case
24+
when Concurrent.on_cruby?
25+
MriAttrVolatile
26+
when Concurrent.on_jruby?
27+
JRubyAttrVolatile
28+
when Concurrent.on_rbx?
29+
RbxAttrVolatile
30+
else
31+
warn 'Possibly unsupported Ruby implementation'
32+
MriAttrVolatile
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)