Skip to content

Commit 45bcb66

Browse files
committed
Ensure each file can be required separately
1 parent 529c078 commit 45bcb66

37 files changed

+178
-84
lines changed

README.md

+6-1
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,12 @@ Everything within this gem can be loaded simply by requiring it:
271271
require 'concurrent'
272272
```
273273

274-
*Requiring only specific abstractions from Concurrent Ruby is not yet supported.*
274+
You can also require a specific abstraction [part of the public documentation](https://ruby-concurrency.github.io/concurrent-ruby/master/index.html) since concurrent-ruby 1.2.0, for example:
275+
```ruby
276+
require 'concurrent/map'
277+
require 'concurrent/atomic/atomic_reference'
278+
require 'concurrent/executor/fixed_thread_pool'
279+
```
275280

276281
To use the tools in the Edge gem it must be required separately:
277282

lib/concurrent-ruby-edge/concurrent/actor/behaviour/abstract.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'concurrent/concern/logging'
2+
require 'concurrent/actor/type_check'
3+
require 'concurrent/actor/internal_delegations'
24

35
module Concurrent
46
module Actor

lib/concurrent-ruby-edge/concurrent/actor/behaviour/awaits.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/buffer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/errors_on_unknown_message.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/executes_context.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/linking.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/pausing.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/removes_child.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/sets_results.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/supervising.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/behaviour/termination.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/behaviour/abstract'
2+
13
module Concurrent
24
module Actor
35
module Behaviour

lib/concurrent-ruby-edge/concurrent/actor/context.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
require 'concurrent/concern/logging'
2+
require 'concurrent/actor/type_check'
3+
require 'concurrent/actor/internal_delegations'
24

35
module Concurrent
46
module Actor

lib/concurrent-ruby-edge/concurrent/actor/core.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
require 'set'
2+
require 'concurrent/actor/type_check'
13
require 'concurrent/concern/logging'
24
require 'concurrent/executors'
5+
require 'concurrent/synchronization/lockable_object'
36

47
module Concurrent
58
module Actor
6-
7-
require 'set'
8-
99
# Core of the actor.
1010
# @note Whole class should be considered private. An user should use {Context}s and {Reference}s only.
1111
# @note devel: core should not block on anything, e.g. it cannot wait on children to terminate

lib/concurrent-ruby-edge/concurrent/actor/default_dead_letter_handler.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/context'
2+
13
module Concurrent
24
module Actor
35
class DefaultDeadLetterHandler < RestartingContext

lib/concurrent-ruby-edge/concurrent/actor/envelope.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/type_check'
2+
13
module Concurrent
24
module Actor
35
class Envelope

lib/concurrent-ruby-edge/concurrent/actor/errors.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/type_check'
2+
13
module Concurrent
24
module Actor
35
Error = Class.new(StandardError)

lib/concurrent-ruby-edge/concurrent/actor/internal_delegations.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require 'logger'
2+
require 'concurrent/actor/public_delegations'
3+
14
module Concurrent
25
module Actor
36
module InternalDelegations

lib/concurrent-ruby-edge/concurrent/actor/reference.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require 'concurrent/actor/type_check'
2+
require 'concurrent/actor/public_delegations'
3+
14
module Concurrent
25
module Actor
36

lib/concurrent-ruby-edge/concurrent/actor/root.rb

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
require 'concurrent/actor/context'
2+
require 'concurrent/actor/core'
3+
14
module Concurrent
25
module Actor
36
# implements the root actor

lib/concurrent-ruby-edge/concurrent/actor/utils/ad_hoc.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/context'
2+
13
module Concurrent
24
module Actor
35
module Utils

lib/concurrent-ruby-edge/concurrent/actor/utils/balancer.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/actor/context'
2+
13
module Concurrent
24
module Actor
35
module Utils

lib/concurrent-ruby-edge/concurrent/actor/utils/broadcast.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'set'
2+
require 'concurrent/actor/context'
23

34
module Concurrent
45
module Actor

lib/concurrent-ruby-edge/concurrent/actor/utils/pool.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'concurrent/actor/utils/balancer'
2+
require 'concurrent/actor/context'
23

34
module Concurrent
45
module Actor

lib/concurrent-ruby-edge/concurrent/channel/buffer/dropping.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'concurrent/channel/buffer/base'
2+
require 'concurrent/channel/buffer/buffered'
23

34
module Concurrent
45
class Channel

lib/concurrent-ruby-edge/concurrent/channel/buffer/sliding.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'concurrent/channel/buffer/base'
2+
require 'concurrent/channel/buffer/buffered'
23

34
module Concurrent
45
class Channel

lib/concurrent-ruby-edge/concurrent/edge/old_channel_integration.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/promises'
2+
13
module Concurrent
24
module Promises
35
module FactoryMethods

lib/concurrent-ruby/concurrent/atomic/atomic_markable_reference.rb

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
require 'concurrent/errors'
12
require 'concurrent/synchronization/object'
23

34
module Concurrent

lib/concurrent-ruby/concurrent/atomic/atomic_reference.rb

+2-80
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
require 'concurrent/utility/native_extension_loader' # load native parts first
22

3+
require 'concurrent/atomic_reference/atomic_direct_update'
34
require 'concurrent/atomic_reference/numeric_cas_wrapper'
5+
require 'concurrent/atomic_reference/mutex_atomic'
46

57
# Shim for TruffleRuby::AtomicReference
68
if Concurrent.on_truffleruby? && !defined?(TruffleRuby::AtomicReference)
@@ -12,79 +14,6 @@ module TruffleRuby
1214

1315
module Concurrent
1416

15-
# Define update methods that use direct paths
16-
#
17-
# @!visibility private
18-
# @!macro internal_implementation_note
19-
module AtomicDirectUpdate
20-
21-
# @!macro atomic_reference_method_update
22-
#
23-
# Pass the current value to the given block, replacing it
24-
# with the block's result. May retry if the value changes
25-
# during the block's execution.
26-
#
27-
# @yield [Object] Calculate a new value for the atomic reference using
28-
# given (old) value
29-
# @yieldparam [Object] old_value the starting value of the atomic reference
30-
# @return [Object] the new value
31-
def update
32-
true until compare_and_set(old_value = get, new_value = yield(old_value))
33-
new_value
34-
end
35-
36-
# @!macro atomic_reference_method_try_update
37-
#
38-
# Pass the current value to the given block, replacing it
39-
# with the block's result. Return nil if the update fails.
40-
#
41-
# @yield [Object] Calculate a new value for the atomic reference using
42-
# given (old) value
43-
# @yieldparam [Object] old_value the starting value of the atomic reference
44-
# @note This method was altered to avoid raising an exception by default.
45-
# Instead, this method now returns `nil` in case of failure. For more info,
46-
# please see: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
47-
# @return [Object] the new value, or nil if update failed
48-
def try_update
49-
old_value = get
50-
new_value = yield old_value
51-
52-
return unless compare_and_set old_value, new_value
53-
54-
new_value
55-
end
56-
57-
# @!macro atomic_reference_method_try_update!
58-
#
59-
# Pass the current value to the given block, replacing it
60-
# with the block's result. Raise an exception if the update
61-
# fails.
62-
#
63-
# @yield [Object] Calculate a new value for the atomic reference using
64-
# given (old) value
65-
# @yieldparam [Object] old_value the starting value of the atomic reference
66-
# @note This behavior mimics the behavior of the original
67-
# `AtomicReference#try_update` API. The reason this was changed was to
68-
# avoid raising exceptions (which are inherently slow) by default. For more
69-
# info: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
70-
# @return [Object] the new value
71-
# @raise [Concurrent::ConcurrentUpdateError] if the update fails
72-
def try_update!
73-
old_value = get
74-
new_value = yield old_value
75-
unless compare_and_set(old_value, new_value)
76-
if $VERBOSE
77-
raise ConcurrentUpdateError, "Update failed"
78-
else
79-
raise ConcurrentUpdateError, "Update failed", ConcurrentUpdateError::CONC_UP_ERR_BACKTRACE
80-
end
81-
end
82-
new_value
83-
end
84-
end
85-
86-
require 'concurrent/atomic_reference/mutex_atomic'
87-
8817
# @!macro atomic_reference
8918
#
9019
# An object reference that may be updated atomically. All read and write
@@ -137,13 +66,6 @@ def try_update!
13766
# @!method try_update!
13867
# @!macro atomic_reference_method_try_update!
13968

140-
141-
# @!macro internal_implementation_note
142-
class ConcurrentUpdateError < ThreadError
143-
# frozen pre-allocated backtrace to speed ConcurrentUpdateError
144-
CONC_UP_ERR_BACKTRACE = ['backtrace elided; set verbose to enable'].freeze
145-
end
146-
14769
# @!macro internal_implementation_note
14870
AtomicReferenceImplementation = case
14971
when Concurrent.on_cruby? && Concurrent.c_extensions_loaded?
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
require 'concurrent/errors'
2+
3+
module Concurrent
4+
5+
# Define update methods that use direct paths
6+
#
7+
# @!visibility private
8+
# @!macro internal_implementation_note
9+
module AtomicDirectUpdate
10+
11+
# @!macro atomic_reference_method_update
12+
#
13+
# Pass the current value to the given block, replacing it
14+
# with the block's result. May retry if the value changes
15+
# during the block's execution.
16+
#
17+
# @yield [Object] Calculate a new value for the atomic reference using
18+
# given (old) value
19+
# @yieldparam [Object] old_value the starting value of the atomic reference
20+
# @return [Object] the new value
21+
def update
22+
true until compare_and_set(old_value = get, new_value = yield(old_value))
23+
new_value
24+
end
25+
26+
# @!macro atomic_reference_method_try_update
27+
#
28+
# Pass the current value to the given block, replacing it
29+
# with the block's result. Return nil if the update fails.
30+
#
31+
# @yield [Object] Calculate a new value for the atomic reference using
32+
# given (old) value
33+
# @yieldparam [Object] old_value the starting value of the atomic reference
34+
# @note This method was altered to avoid raising an exception by default.
35+
# Instead, this method now returns `nil` in case of failure. For more info,
36+
# please see: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
37+
# @return [Object] the new value, or nil if update failed
38+
def try_update
39+
old_value = get
40+
new_value = yield old_value
41+
42+
return unless compare_and_set old_value, new_value
43+
44+
new_value
45+
end
46+
47+
# @!macro atomic_reference_method_try_update!
48+
#
49+
# Pass the current value to the given block, replacing it
50+
# with the block's result. Raise an exception if the update
51+
# fails.
52+
#
53+
# @yield [Object] Calculate a new value for the atomic reference using
54+
# given (old) value
55+
# @yieldparam [Object] old_value the starting value of the atomic reference
56+
# @note This behavior mimics the behavior of the original
57+
# `AtomicReference#try_update` API. The reason this was changed was to
58+
# avoid raising exceptions (which are inherently slow) by default. For more
59+
# info: https://github.com/ruby-concurrency/concurrent-ruby/pull/336
60+
# @return [Object] the new value
61+
# @raise [Concurrent::ConcurrentUpdateError] if the update fails
62+
def try_update!
63+
old_value = get
64+
new_value = yield old_value
65+
unless compare_and_set(old_value, new_value)
66+
if $VERBOSE
67+
raise ConcurrentUpdateError, "Update failed"
68+
else
69+
raise ConcurrentUpdateError, "Update failed", ConcurrentUpdateError::CONC_UP_ERR_BACKTRACE
70+
end
71+
end
72+
new_value
73+
end
74+
end
75+
end

lib/concurrent-ruby/concurrent/atomic_reference/mutex_atomic.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/atomic_reference/atomic_direct_update'
2+
require 'concurrent/atomic_reference/numeric_cas_wrapper'
13
require 'concurrent/synchronization/safe_initialization'
24

35
module Concurrent

lib/concurrent-ruby/concurrent/collection/lock_free_stack.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/synchronization/object'
2+
13
module Concurrent
24

35
# @!macro warn.edge

lib/concurrent-ruby/concurrent/errors.rb

+5
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,9 @@ def initialize(errors, message = "#{errors.size} errors")
6666
end
6767
end
6868

69+
# @!macro internal_implementation_note
70+
class ConcurrentUpdateError < ThreadError
71+
# frozen pre-allocated backtrace to speed ConcurrentUpdateError
72+
CONC_UP_ERR_BACKTRACE = ['backtrace elided; set verbose to enable'].freeze
73+
end
6974
end

lib/concurrent-ruby/concurrent/synchronization/mutex_lockable_object.rb

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'concurrent/synchronization/abstract_lockable_object'
2+
13
module Concurrent
24
# noinspection RubyInstanceVariableNamingConvention
35
module Synchronization

0 commit comments

Comments
 (0)