Browse files

This library *does* depend on thread (rubygems 1.6+ does not require …

…this for you)

Conflicts:

	lib/system_timer.rb
  • Loading branch information...
1 parent adc6ccc commit 4ee32e8db3a2e5a5aeaa419ab6568f44c9b274de @ph7 ph7 committed Mar 20, 2011
Showing with 15 additions and 14 deletions.
  1. +15 −14 lib/system_timer.rb
View
29 lib/system_timer.rb
@@ -5,6 +5,7 @@
else
require 'rubygems'
+require 'thread'
require 'timeout'
require 'forwardable'
require 'monitor'
@@ -38,12 +39,12 @@ module SystemTimer
@timer_pool = ConcurrentTimerPool.new
@monitor = Monitor.new
end
-
+
class << self
- attr_reader :timer_pool
-
- # Executes the method's block. If the block execution terminates before
- # +seconds+ seconds has passed, it returns true. If not, it terminates
+ attr_reader :timer_pool
+
+ # Executes the method's block. If the block execution terminates before
+ # +seconds+ seconds has passed, it returns true. If not, it terminates
# the execution and raises a +Timeout::Error+.
def timeout_after(seconds, exception_class = nil)
new_timer = nil # just for scope
@@ -68,16 +69,16 @@ def timeout_after(seconds, exception_class = nil)
if next_interval
install_next_timer next_interval
else
- restore_original_configuration
+ restore_original_configuration
end
end
end
-
+
# Backward compatibility with timeout.rb
- alias timeout timeout_after
-
+ alias timeout timeout_after
+
protected
-
+
def install_ruby_sigalrm_handler #:nodoc:
@original_ruby_sigalrm_handler = trap('SIGALRM') do
@monitor.synchronize do
@@ -86,25 +87,25 @@ def install_ruby_sigalrm_handler #:nodoc:
end
end
end
-
+
def restore_original_ruby_sigalrm_handler #:nodoc:
trap('SIGALRM', original_ruby_sigalrm_handler || 'DEFAULT')
ensure
reset_original_ruby_sigalrm_handler
end
-
+
def original_ruby_sigalrm_handler #:nodoc:
@original_ruby_sigalrm_handler
end
-
+
def reset_original_ruby_sigalrm_handler #:nodoc:
@original_ruby_sigalrm_handler = nil
end
def debug(message) #:nodoc
puts message if debug_enabled?
end
-
+
end
end

0 comments on commit 4ee32e8

Please sign in to comment.