Skip to content

Commit

Permalink
Rubinius doesn't know Thread.kill, use #kill instead. [bug]
Browse files Browse the repository at this point in the history
  • Loading branch information
trans committed Dec 27, 2011
1 parent fc61923 commit f833f45
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -1,3 +1,4 @@
.rbx
.rdoc
.reap/digest
.yardoc
Expand All @@ -8,3 +9,4 @@ tmp
web
work/sandbox
work/trash
Gemfile.lock
5 changes: 3 additions & 2 deletions lib/standard/facets/timer.rb
Expand Up @@ -116,7 +116,8 @@ def limit( time_limit=nil )
# Kill time limit thread, if any.
def defuse
if @timer_thread
Thread.kill @timer_thread
#Thread.kill @timer_thread
@timer_thread.kill
@timer_thread = nil
end
end
Expand Down Expand Up @@ -204,4 +205,4 @@ def stop

end #class Timer

# Copyright (c) 2004 Thomas Sawyer (Ruby License)
# Copyright (c) 2004 Rubyworks
32 changes: 22 additions & 10 deletions test/standard/test_timer.rb
Expand Up @@ -3,20 +3,32 @@
test_case Timer do

class_method :time do
test do
Timer.time { |timer|
test "can keep time of a block" do
Timer.time do |timer|
timer.total_time.round.assert == 0
sleep 1
timer.total_time.round.assert == 1
end
end

test "can be stopped" do
Timer.time do |timer|
sleep 0.4
timer.stop
timer.total_time.round.assert == 1
sleep 1
timer.total_time.round.assert == 1
sleep 0.6
timer.total_time.round.assert == 0
end
end

test "timer can be started again" do
Timer.time do |timer|
timer.stop
sleep 0.5
timer.total_time.round.assert == 0
timer.start
timer.total_time.round.assert == 1
sleep 1
timer.total_time.round.assert == 2
}
timer.total_time.round.assert == 1
end
end
end

Expand All @@ -31,7 +43,7 @@
end

test "in time" do
t = Timer.new(1)
t = Timer.new(2)
t.start
sleep 0.5
t.stop
Expand All @@ -40,7 +52,7 @@

method :stop do
test "in time" do
t = Timer.new(1)
t = Timer.new(2)
t.start
sleep 0.5
t.stop
Expand Down

0 comments on commit f833f45

Please sign in to comment.