Skip to content

Commit 55ce8f4

Browse files
committed
Synchronized initialization of TimerTask.
1 parent cf9213e commit 55ce8f4

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

lib/concurrent/timer_task.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -187,18 +187,7 @@ class TimerTask < RubyExecutorService
187187
# @see Concurrent::Dereferenceable# set_deref_options
188188
def initialize(opts = {}, &task)
189189
raise ArgumentError.new('no block given') unless block_given?
190-
191-
super(&:nil)
192-
init_mutex(self)
193-
set_deref_options(opts)
194-
195-
self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
196-
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
197-
@run_now = opts[:now] || opts[:run_now]
198-
@executor = Concurrent::SafeTaskExecutor.new(task)
199-
@running = Concurrent::AtomicBoolean.new(false)
200-
201-
self.observers = CopyOnNotifyObserverSet.new
190+
super
202191
end
203192

204193
# Is the executor running?
@@ -282,6 +271,19 @@ def timeout_interval=(value)
282271

283272
protected
284273

274+
def ns_initialize(opts = {}, &task)
275+
init_mutex(self)
276+
set_deref_options(opts)
277+
278+
self.execution_interval = opts[:execution] || opts[:execution_interval] || EXECUTION_INTERVAL
279+
self.timeout_interval = opts[:timeout] || opts[:timeout_interval] || TIMEOUT_INTERVAL
280+
@run_now = opts[:now] || opts[:run_now]
281+
@executor = Concurrent::SafeTaskExecutor.new(task)
282+
@running = Concurrent::AtomicBoolean.new(false)
283+
284+
self.observers = CopyOnNotifyObserverSet.new
285+
end
286+
285287
# @!visibility private
286288
def shutdown_execution
287289
@running.make_false

0 commit comments

Comments
 (0)