lib/timeout/extensions.rb in timeout-extensions-0.1.0 vs lib/timeout/extensions.rb in timeout-extensions-0.1.1
- old
+ new
@@ -1,6 +1,7 @@
require "timeout/extensions/version"
+require "timeout"
# Core extensions to Thread
#
# Adds accessors to customize timeout and sleep within a thread,
# if you have a better friendlier implementation of both methods,
@@ -45,6 +46,18 @@
# this is an hack so that calling "sleep(2)" works. Amazingly, the message doesn't get
# sent to Kernel.sleep code path.
# https://bugs.ruby-lang.org/issues/12535
#
::Object.prepend KernelMethods
+end
+
+module Timeout
+ def self.backend(handler)
+ default_handler = Thread.current.timeout_handler
+ begin
+ Thread.current.timeout_handler = handler
+ yield
+ ensure
+ Thread.current.timeout_handler = default_handler
+ end
+ end
end