diff options
author | Samuel Williams <[email protected]> | 2021-02-11 19:17:54 +1300 |
---|---|---|
committer | Samuel Williams <[email protected]> | 2021-03-30 18:38:42 +1300 |
commit | 4c53dc970bf82e4c5fb237be4b2404bcb07496d2 (patch) | |
tree | 8df121b7255da00297a2dbd9c126302abcade685 /lib/timeout.rb | |
parent | 93753d7ee738475f7445e5cfc405756a4fb7f850 (diff) |
Add hook for `Timeout.timeout`.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/4173
Diffstat (limited to 'lib/timeout.rb')
-rw-r--r-- | lib/timeout.rb | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/lib/timeout.rb b/lib/timeout.rb index 9026ad51d6..43f26f5869 100644 --- a/lib/timeout.rb +++ b/lib/timeout.rb @@ -76,9 +76,15 @@ module Timeout # Note that this is both a method of module Timeout, so you can <tt>include # Timeout</tt> into your classes so they have a #timeout method, as well as # a module method, so you can call it directly as Timeout.timeout(). - def timeout(sec, klass = nil, message = nil) #:yield: +sec+ + def timeout(sec, klass = nil, message = nil, &block) #:yield: +sec+ return yield(sec) if sec == nil or sec.zero? + message ||= "execution expired".freeze + + if scheduler = Fiber.scheduler and scheduler.respond_to?(:timeout_raise) + return scheduler.timeout_raise(sec, klass || Error, message, &block) + end + from = "from #{caller_locations(1, 1)[0]}" if $DEBUG e = Error bl = proc do |exception| |