Skip to content

Instantly share code, notes, and snippets.

@robholland
Created April 15, 2009 13:38
Show Gist options
  • Save robholland/95769 to your computer and use it in GitHub Desktop.
Save robholland/95769 to your computer and use it in GitHub Desktop.
it "runs nested ensure clauses" do
thread = ThreadSpecs.nested_dying_thread_ensures(@method) { ScratchPad.record :in_ensure_clause }
thread.join
ScratchPad.recorded.should == :in_ensure_clause
end
def self.nested_dying_thread_ensures(kill_method_name=:kill)
o = Thread.new do
begin
t = Thread.new do
begin
sleep
ensure
yield
end
end
Thread.current.send(kill_method_name)
ensure
t.kill
t.join
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment