Skip to content

Commit

Permalink
merged updates from billdueber
Browse files Browse the repository at this point in the history
  • Loading branch information
jdantonio committed Jun 10, 2014
2 parents fe39e28 + edcb76b commit 636ece4
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ task.value #=> 25.96
* [Ravil Bayramgalin](https://github.com/brainopia)
* [Larry Lv](https://github.com/larrylv)
* [Giuseppe Capizzi](https://github.com/gcapizzi)
* [Bill Dueber](https://github.com/billdueber)
* [Brian Shirai](https://github.com/brixen)
* [Chip Miller](https://github.com/chip-miller)
* [Jamie Hodge](https://github.com/jamiehodge)
Expand Down
1 change: 0 additions & 1 deletion lib/concurrent/executor/ruby_thread_pool_executor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ def execute(*args, &task)

# @!visibility private
def shutdown_execution
@queue.clear
if @pool.empty?
stopped_event.set
else
Expand Down
7 changes: 6 additions & 1 deletion lib/concurrent/executor/timer_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def post(intended_time, *args, &task)

end

alias_method :kill, :shutdown
# For a timer, #kill is like an orderly shutdown, except we need to manually
# (and destructively) clear the queue first
def kill
@queue.clear
shutdown
end

# Calculate an Epoch time with milliseconds at which to execute a
# task. If the given time is a `Time` object it will be converted
Expand Down
30 changes: 30 additions & 0 deletions spec/concurrent/executor/thread_pool_shared.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,36 @@
end
end

context '#shutdown followed by #wait_for_termination' do
it "allows in-progress tasks to complete" do
@expected = false
subject.post{ sleep 0.1; @expected = true }
subject.shutdown
subject.wait_for_termination(1)
@expected.should be_true
end

it 'allows pending tasks to complete' do
@expected = false
subject.post{ sleep(0.1) }
subject.post{ sleep(0.1); @expected = true }
subject.shutdown
subject.wait_for_termination(1)
@expected.should be_true
end

it "stops accepting/running new tasks" do
@expected = :start
subject.post{ sleep(0.1) }
subject.post{ sleep(0.1); @expected = :should_be_run }
subject.shutdown
subject.post{ @expected = :should_not_be_run }
subject.wait_for_termination(1)
@expected.should == :should_be_run
end
end


context '#kill' do

it 'stops accepting new tasks' do
Expand Down

0 comments on commit 636ece4

Please sign in to comment.