mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
timeout.rb: current_target
* lib/timeout.rb (Timeout::ExitException#target): rename attribute. * lib/timeout.rb (Timeout::ExitException.current_target): extract a method to achieve the target. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44520 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
ed9f79df1a
commit
82b1790df0
1 changed files with 7 additions and 3 deletions
|
@ -26,17 +26,21 @@ module Timeout
|
|||
class Error < RuntimeError
|
||||
end
|
||||
class ExitException < ::Exception # :nodoc:
|
||||
attr_reader :thread
|
||||
attr_reader :target
|
||||
|
||||
def self.current_target
|
||||
Thread.current
|
||||
end
|
||||
|
||||
def self.catch
|
||||
exc = new
|
||||
exc.instance_variable_set(:@thread, Thread.current)
|
||||
exc.instance_variable_set(:@target, current_target)
|
||||
exc.freeze
|
||||
::Kernel.catch(exc) {yield exc}
|
||||
end
|
||||
|
||||
def exception(*)
|
||||
throw(self, caller) if self.thread == Thread.current
|
||||
throw(self, caller) if self.target == self.class.current_target
|
||||
self
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue