Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 1908a6e

Browse filesBrowse files
committed
Cancel the task instead of changing @running
1 parent f3d097c commit 1908a6e
Copy full SHA for 1908a6e

File tree

1 file changed

+14
-5
lines changed
Filter options

1 file changed

+14
-5
lines changed

‎lib/concurrent-ruby/concurrent/timer_task.rb

Copy file name to clipboardExpand all lines: lib/concurrent-ruby/concurrent/timer_task.rb
+14-5Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,16 @@ def timeout_interval=(value)
256256
warn 'TimerTask timeouts are now ignored as these were not able to be implemented correctly'
257257
end
258258

259+
def shutdown
260+
@task.cancel if @task # must happen outside of synchronization
261+
super
262+
end
263+
264+
def kill
265+
@task.cancel if @task # must happen outside of synchronization
266+
super
267+
end
268+
259269
private :post, :<<
260270

261271
private
@@ -270,6 +280,7 @@ def ns_initialize(opts, &task)
270280
@run_now = opts[:now] || opts[:run_now]
271281
@executor = Concurrent::SafeTaskExecutor.new(task)
272282
@running = Concurrent::AtomicBoolean.new(false)
283+
@task = nil
273284
@value = nil
274285

275286
self.observers = Collection::CopyOnNotifyObserverSet.new
@@ -278,26 +289,24 @@ def ns_initialize(opts, &task)
278289
# @!visibility private
279290
def ns_shutdown_execution
280291
@running.make_false
281-
@running = Concurrent::AtomicBoolean.new(false)
282292
super
283293
end
284294

285295
# @!visibility private
286296
def ns_kill_execution
287297
@running.make_false
288-
@running = Concurrent::AtomicBoolean.new(false)
289298
super
290299
end
291300

292301
# @!visibility private
293302
def schedule_next_task(interval = execution_interval)
294-
ScheduledTask.execute(interval, args: [Concurrent::Event.new, @running], &method(:execute_task))
303+
@task = ScheduledTask.execute(interval, args: [Concurrent::Event.new], &method(:execute_task))
295304
nil
296305
end
297306

298307
# @!visibility private
299-
def execute_task(completion, continue_running)
300-
return nil unless continue_running.true?
308+
def execute_task(completion)
309+
return nil unless @running.true?
301310
_success, value, reason = @executor.execute(self)
302311
if completion.try?
303312
self.value = value

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.