Skip to content

Commit 9906e23

Browse files
committed
Add helper methods for deprecations
1 parent a8fe298 commit 9906e23

17 files changed

+86
-58
lines changed

lib/concurrent/agent.rb

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
require 'concurrent/observable'
44
require 'concurrent/logging'
55
require 'concurrent/executor/executor'
6+
require 'concurrent/utility/deprecation'
67

78
module Concurrent
89

@@ -14,6 +15,7 @@ class Agent
1415
include Dereferenceable
1516
include Observable
1617
include Logging
18+
include Deprecation
1719

1820
attr_reader :timeout, :io_executor, :fast_executor
1921

@@ -115,21 +117,21 @@ def post(&block)
115117
# @yieldreturn [Object] the new value
116118
# @return [true, nil] nil when no block is given
117119
def post_off(timeout = nil, &block)
118-
warn '[DEPRECATED] post_off with timeout options is deprecated and will be removed'
119120
task = if timeout
120-
lambda do |value|
121-
future = Future.execute do
122-
block.call(value)
123-
end
124-
if future.wait(timeout)
125-
future.value!
126-
else
127-
raise Concurrent::TimeoutError
128-
end
129-
end
130-
else
131-
block
132-
end
121+
deprecated 'post_off with option timeout options is deprecated and will be removed'
122+
lambda do |value|
123+
future = Future.execute do
124+
block.call(value)
125+
end
126+
if future.wait(timeout)
127+
future.value!
128+
else
129+
raise Concurrent::TimeoutError
130+
end
131+
end
132+
else
133+
block
134+
end
133135
post_on(@io_executor, &task)
134136
end
135137

lib/concurrent/atomic/condition.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
require 'concurrent/utility/monotonic_time'
2+
require 'concurrent/utility/deprecation'
23

34
module Concurrent
45

@@ -14,6 +15,7 @@ module Concurrent
1415
#
1516
# @deprecated
1617
class Condition
18+
include Deprecation
1719

1820
class Result
1921
def initialize(remaining_time)
@@ -39,7 +41,7 @@ def timed_out?
3941
end
4042

4143
def initialize
42-
warn '[DEPRECATED] Will be replaced with Synchronization::Object in v1.0.'
44+
deprecated 'Will be replaced with Synchronization::Object in v1.0.'
4345
@condition = ConditionVariable.new
4446
end
4547

lib/concurrent/configuration.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
require 'concurrent/at_exit'
55
require 'concurrent/executors'
66
require 'concurrent/utility/processor_count'
7+
require 'concurrent/utility/deprecation'
78

89
module Concurrent
910
extend Logging
11+
extend Deprecation
1012

1113
# Suppresses all output when used for logging.
1214
NULL_LOGGER = lambda { |level, progname, message = nil, &block| }
13-
private_constant :NULL_LOGGER
1415

1516
# @!visibility private
1617
GLOBAL_LOGGER = AtomicReference.new(NULL_LOGGER)
@@ -60,21 +61,21 @@ def self.disable_at_exit_hooks!
6061
end
6162

6263
def self.disable_executor_auto_termination!
63-
warn '[DEPRECATED] Use Concurrent.disable_at_exit_hooks! instead'
64+
deprecated_method 'disable_executor_auto_termination!', 'disable_at_exit_hooks!'
6465
disable_at_exit_hooks!
6566
end
6667

6768
# @return [true,false]
6869
# @see .disable_executor_auto_termination!
6970
def self.disable_executor_auto_termination?
70-
warn '[DEPRECATED] Use Concurrent::AtExit.enabled? instead'
71+
deprecated_method 'disable_executor_auto_termination?', 'Concurrent::AtExit.enabled?'
7172
AtExit.enabled?
7273
end
7374

7475
# terminates all pools and blocks until they are terminated
7576
# @see .disable_executor_auto_termination!
7677
def self.terminate_pools!
77-
warn '[DEPRECATED] Use Concurrent::AtExit.run instead'
78+
deprecated_method 'terminate_pools!', 'Concurrent::AtExit.run'
7879
AtExit.run
7980
end
8081

@@ -139,6 +140,7 @@ def self.new_io_executor(opts = {})
139140

140141
# A gem-level configuration object.
141142
class Configuration
143+
include Deprecation
142144

143145
# Create a new configuration object.
144146
def initialize
@@ -148,6 +150,7 @@ def initialize
148150
# @deprecated Use Concurrent::NULL_LOGGER instead
149151
def no_logger
150152
warn '[DEPRECATED] Use Concurrent::NULL_LOGGER instead'
153+
deprecated_method 'Concurrent.configuration.no_logger', 'Concurrent::NULL_LOGGER'
151154
NULL_LOGGER
152155
end
153156

@@ -156,7 +159,7 @@ def no_logger
156159
#
157160
# @deprecated Use Concurrent.global_logger instead
158161
def logger
159-
warn '[DEPRECATED] Use Concurrent.global_logger instead'
162+
deprecated_method 'Concurrent.configuration.logger', 'Concurrent.global_logger'
160163
Concurrent.global_logger.value
161164
end
162165

@@ -165,65 +168,65 @@ def logger
165168
#
166169
# @deprecated Use Concurrent.global_logger instead
167170
def logger=(value)
168-
warn '[DEPRECATED] Use Concurrent.global_logger instead'
171+
deprecated_method 'Concurrent.configuration.logger=', 'Concurrent.global_logger='
169172
Concurrent.global_logger = value
170173
end
171174

172175
# @deprecated Use Concurrent.global_io_executor instead
173176
def global_task_pool
174-
warn '[DEPRECATED] Use Concurrent.global_io_executor instead'
177+
deprecated_method 'Concurrent.configuration.global_task_pool', 'Concurrent.global_io_executor'
175178
Concurrent.global_io_executor
176179
end
177180

178181
# @deprecated Use Concurrent.global_fast_executor instead
179182
def global_operation_pool
180-
warn '[DEPRECATED] Use Concurrent.global_fast_executor instead'
183+
deprecated_method 'Concurrent.configuration.global_operation_pool', 'Concurrent.global_fast_executor'
181184
Concurrent.global_fast_executor
182185
end
183186

184187
# @deprecated Use Concurrent.global_timer_set instead
185188
def global_timer_set
186-
warn '[DEPRECATED] Use Concurrent.global_timer_set instead'
189+
deprecated_method 'Concurrent.configuration.global_timer_set', 'Concurrent.global_timer_set'
187190
Concurrent.global_timer_set
188191
end
189192

190193
# @deprecated Replacing global thread pools is deprecated.
191194
# Use the :executor constructor option instead.
192195
def global_task_pool=(executor)
193-
warn '[DEPRECATED] Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
196+
deprecated 'Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
194197
GLOBAL_IO_EXECUTOR.reconfigure { executor } or
195198
raise ConfigurationError.new('global task pool was already set')
196199
end
197200

198201
# @deprecated Replacing global thread pools is deprecated.
199202
# Use the :executor constructor option instead.
200203
def global_operation_pool=(executor)
201-
warn '[DEPRECATED] Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
204+
deprecated 'Replacing global thread pools is deprecated. Use the :executor constructor option instead.'
202205
GLOBAL_FAST_EXECUTOR.reconfigure { executor } or
203206
raise ConfigurationError.new('global operation pool was already set')
204207
end
205208

206209
# @deprecated Use Concurrent.new_io_executor instead
207210
def new_task_pool
208-
warn '[DEPRECATED] Use Concurrent.new_io_executor instead'
211+
deprecated_method 'Concurrent.configuration.new_task_pool', 'Concurrent.new_io_executor'
209212
Concurrent.new_io_executor
210213
end
211214

212215
# @deprecated Use Concurrent.new_fast_executor instead
213216
def new_operation_pool
214-
warn '[DEPRECATED] Use Concurrent.new_fast_executor instead'
217+
deprecated_method 'Concurrent.configuration.new_operation_pool', 'Concurrent.new_fast_executor'
215218
Concurrent.new_fast_executor
216219
end
217220

218221
# @deprecated Use Concurrent.disable_auto_termination_of_global_executors! instead
219222
def auto_terminate=(value)
220-
warn '[DEPRECATED] Use Concurrent.disable_auto_termination_of_global_executors! instead'
223+
deprecated_method 'Concurrent.configuration.auto_terminate=', 'Concurrent.disable_auto_termination_of_global_executors!'
221224
Concurrent.disable_auto_termination_of_global_executors! if !value
222225
end
223226

224227
# @deprecated Use Concurrent.auto_terminate_global_executors? instead
225228
def auto_terminate
226-
warn '[DEPRECATED] Use Concurrent.auto_terminate_global_executors? instead'
229+
deprecated_method 'Concurrent.configuration.auto_terminate', 'Concurrent.auto_terminate_global_executors?'
227230
Concurrent.auto_terminate_global_executors?
228231
end
229232
end

lib/concurrent/executor/executor.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
require 'concurrent/executor/executor_service'
2+
require 'concurrent/utility/deprecation'
23

34
module Concurrent
45

56
module Executor
7+
extend Deprecation
68

79
# Get the requested `Executor` based on the values set in the options hash.
810
#
@@ -25,12 +27,12 @@ def self.executor_from_options(opts = {}) # :nodoc:
2527
end
2628
when opts.key?(:operation) || opts.key?(:task)
2729
if opts[:operation] == true || opts[:task] == false
28-
Kernel.warn '[DEPRECATED] use `executor: :fast` instead'
30+
deprecated 'use `executor: :fast` instead'
2931
return Concurrent.global_fast_executor
3032
end
3133

3234
if opts[:operation] == false || opts[:task] == true
33-
Kernel.warn '[DEPRECATED] use `executor: :io` instead'
35+
deprecated 'use `executor: :io` instead'
3436
return Concurrent.global_io_executor
3537
end
3638

@@ -49,10 +51,10 @@ def self.executor(executor_identifier)
4951
when :immediate
5052
Concurrent.global_immediate_executor
5153
when :operation
52-
Kernel.warn '[DEPRECATED] use `executor: :fast` instead'
54+
deprecated 'use `executor: :fast` instead'
5355
Concurrent.global_fast_executor
5456
when :task
55-
Kernel.warn '[DEPRECATED] use `executor: :io` instead'
57+
deprecated 'use `executor: :io` instead'
5658
Concurrent.global_io_executor
5759
when Concurrent::ExecutorService
5860
executor_identifier

lib/concurrent/executor/executor_service.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
require 'concurrent/at_exit'
44
require 'concurrent/atomic/event'
55
require 'concurrent/synchronization'
6+
require 'concurrent/utility/deprecation'
67

78
module Concurrent
89

910
module ExecutorService
1011
include Logging
12+
include Deprecation
1113

1214
# @!macro [attach] executor_service_method_post
1315
#

lib/concurrent/executor/java_cached_thread_pool.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def initialize(opts = {})
2424

2525
def ns_initialize(opts)
2626
@fallback_policy = opts.fetch(:fallback_policy, opts.fetch(:overflow_policy, :abort))
27-
warn '[DEPRECATED] :overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
27+
deprecated ':overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
2828
@max_queue = 0
2929

3030
raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICY_CLASSES.keys.include?(@fallback_policy)

lib/concurrent/executor/java_thread_pool_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def ns_initialize(opts)
139139
idletime = opts.fetch(:idletime, DEFAULT_THREAD_IDLETIMEOUT).to_i
140140
@max_queue = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
141141
@fallback_policy = opts.fetch(:fallback_policy, opts.fetch(:overflow_policy, :abort))
142-
warn '[DEPRECATED] :overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
142+
deprecated ' :overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
143143

144144
raise ArgumentError.new('max_threads must be greater than zero') if max_length <= 0
145145
raise ArgumentError.new('min_threads cannot be less than zero') if min_length < 0

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def ns_initialize(opts)
135135
@max_queue = opts.fetch(:max_queue, DEFAULT_MAX_QUEUE_SIZE).to_i
136136
@fallback_policy = opts.fetch(:fallback_policy, opts.fetch(:overflow_policy, :abort))
137137
raise ArgumentError.new("#{@fallback_policy} is not a valid fallback policy") unless FALLBACK_POLICIES.include?(@fallback_policy)
138-
warn '[DEPRECATED] :overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
138+
deprecated ':overflow_policy is deprecated terminology, please use :fallback_policy instead' if opts.has_key?(:overflow_policy)
139139

140140
raise ArgumentError.new('max_threads must be greater than zero') if @max_length <= 0
141141
raise ArgumentError.new('min_threads cannot be less than zero') if @min_length < 0

lib/concurrent/executor/simple_executor_service.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def ns_initialize
102102
class PerThreadExecutor < SimpleExecutorService
103103

104104
def initialize
105-
warn '[DEPRECATED] use SimpleExecutorService instead'
105+
deprecated 'use SimpleExecutorService instead'
106106
super
107107
end
108108
end

lib/concurrent/executor/timer_set.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
require 'concurrent/executor/executor_service'
66
require 'concurrent/executor/single_thread_executor'
77
require 'concurrent/utility/monotonic_time'
8+
require 'concurrent/utility/deprecation'
89

910
module Concurrent
1011

@@ -14,6 +15,7 @@ module Concurrent
1415
#
1516
# @!macro monotonic_clock_warning
1617
class TimerSet < RubyExecutorService
18+
extend Deprecation
1719

1820
# Create a new set of timed tasks.
1921
#
@@ -82,7 +84,7 @@ def kill
8284
# @!visibility private
8385
def self.calculate_delay!(delay)
8486
if delay.is_a?(Time)
85-
warn '[DEPRECATED] Use an interval not a clock time; schedule is now based on a monotonic clock'
87+
deprecated 'Use an interval not a clock time; schedule is now based on a monotonic clock'
8688
now = Time.now
8789
raise ArgumentError.new('schedule time must be in the future') if delay <= now
8890
delay.to_f - now.to_f

0 commit comments

Comments
 (0)