Skip to content

Commit 49417cb

Browse files
committed
Merge branch 'billdueber-isolated_threadpool_fix'
2 parents fe39e28 + 636ece4 commit 49417cb

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ task.value #=> 25.96
140140
* [Ravil Bayramgalin](https://github.com/brainopia)
141141
* [Larry Lv](https://github.com/larrylv)
142142
* [Giuseppe Capizzi](https://github.com/gcapizzi)
143+
* [Bill Dueber](https://github.com/billdueber)
143144
* [Brian Shirai](https://github.com/brixen)
144145
* [Chip Miller](https://github.com/chip-miller)
145146
* [Jamie Hodge](https://github.com/jamiehodge)

lib/concurrent/executor/ruby_thread_pool_executor.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ def execute(*args, &task)
172172

173173
# @!visibility private
174174
def shutdown_execution
175-
@queue.clear
176175
if @pool.empty?
177176
stopped_event.set
178177
else

lib/concurrent/executor/timer_set.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ def post(intended_time, *args, &task)
6161

6262
end
6363

64-
alias_method :kill, :shutdown
64+
# For a timer, #kill is like an orderly shutdown, except we need to manually
65+
# (and destructively) clear the queue first
66+
def kill
67+
@queue.clear
68+
shutdown
69+
end
6570

6671
# Calculate an Epoch time with milliseconds at which to execute a
6772
# task. If the given time is a `Time` object it will be converted

spec/concurrent/executor/thread_pool_shared.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,36 @@
100100
end
101101
end
102102

103+
context '#shutdown followed by #wait_for_termination' do
104+
it "allows in-progress tasks to complete" do
105+
@expected = false
106+
subject.post{ sleep 0.1; @expected = true }
107+
subject.shutdown
108+
subject.wait_for_termination(1)
109+
@expected.should be_true
110+
end
111+
112+
it 'allows pending tasks to complete' do
113+
@expected = false
114+
subject.post{ sleep(0.1) }
115+
subject.post{ sleep(0.1); @expected = true }
116+
subject.shutdown
117+
subject.wait_for_termination(1)
118+
@expected.should be_true
119+
end
120+
121+
it "stops accepting/running new tasks" do
122+
@expected = :start
123+
subject.post{ sleep(0.1) }
124+
subject.post{ sleep(0.1); @expected = :should_be_run }
125+
subject.shutdown
126+
subject.post{ @expected = :should_not_be_run }
127+
subject.wait_for_termination(1)
128+
@expected.should == :should_be_run
129+
end
130+
end
131+
132+
103133
context '#kill' do
104134

105135
it 'stops accepting new tasks' do

0 commit comments

Comments
 (0)