Skip to content

Commit 0518797

Browse files
committed
TimerSet now posts through Executor.
1 parent 317c7fe commit 0518797

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

lib/concurrent/executor/timer_set.rb

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,12 @@ def initialize(opts = {})
4141
#
4242
# @raise [ArgumentError] if the intended execution time is not in the future
4343
# @raise [ArgumentError] if no block is given
44-
def post(intended_time, &block)
45-
mutex.synchronize do
46-
return false unless running?
47-
raise ArgumentError.new('no block given') unless block_given?
48-
time = TimerSet.calculate_schedule_time(intended_time).to_f
49-
50-
if (time - Time.now.to_f) <= 0.01
51-
@executor.post(&block)
52-
else
53-
@queue.push(Task.new(time, block))
54-
end
44+
def post(intended_time, &task)
45+
time = TimerSet.calculate_schedule_time(intended_time).to_f
46+
if super(time, &task)
47+
check_processing_thread!
48+
true
5549
end
56-
check_processing_thread!
57-
true
5850
end
5951

6052
# Begin an orderly shutdown. Tasks already in the queue will be executed,
@@ -110,6 +102,14 @@ def <=>(other)
110102
end
111103
end
112104

105+
def execute(time, &task)
106+
if (time - Time.now.to_f) <= 0.01
107+
@executor.post(&task)
108+
else
109+
@queue.push(Task.new(time, task))
110+
end
111+
end
112+
113113
# Check the status of the processing thread. This thread is responsible
114114
# for monitoring the internal task queue and sending tasks to the
115115
# executor when it is time for them to be processed. If there is no

0 commit comments

Comments
 (0)