Skip to content

Commit ff9c671

Browse files
committed
Concurrent.timer now returns an IVar.
1 parent b5d4432 commit ff9c671

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

lib/concurrent/executor/timer_set.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def initialize(time, args, task)
3535
end
3636
end
3737

38+
# @!visibility private
3839
def time
3940
synchronize { @time }
4041
end
@@ -107,7 +108,9 @@ def post(delay, *args, &task)
107108
@task_executor.post{ task.execute }
108109
else
109110
@queue.push(task)
110-
@timer_executor.post(&method(:process_tasks))
111+
# `process_tasks` method will run until queue is empty
112+
# only post the process method when the queue is empty
113+
@timer_executor.post(&method(:process_tasks)) if @queue.size == 1
111114
end
112115

113116
@condition.set

lib/concurrent/utility/timer.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ module Concurrent
1515
def timer(seconds, *args, &block)
1616
raise ArgumentError.new('no block given') unless block_given?
1717
raise ArgumentError.new('interval must be greater than or equal to zero') if seconds < 0
18-
1918
Concurrent.configuration.global_timer_set.post(seconds, *args, &block)
20-
true
2119
end
2220
module_function :timer
2321
end

0 commit comments

Comments
 (0)