timeout 0.3.2 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/lib/timeout.rb +16 -20
  4. data/timeout.gemspec +3 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 201c519af67a105d6bd6e83e6f983cb7ab41c2968be1433ab9421498a1a1cfc3
4
- data.tar.gz: 0d9b5e39dda0333010013508b000eb95c584f5959932665b5fa7c3cb23d64112
3
+ metadata.gz: 2c10c971f22da3b85c5219ff6c8d8f018de3b04ba2ae7c64c4f368bd9e2ebdb7
4
+ data.tar.gz: 26d74226d36fa316564ec6665218bb1665accbbe420305451285d0ff7799bc16
5
5
  SHA512:
6
- metadata.gz: 754ad7872462dcc555b91c1c589662e3e11f0bdbd2057b336e813e20743bb24e9ac74604c1dafea0159690f9cd480b57039fa878b5d523fb3662499560f99f2a
7
- data.tar.gz: 17a3815d1a1fd685e2b24a3b41717292b9e6c5e370156d6083788fb4594179a29ec9933df106b955a1bd1cfb479097aac462b161d429b55c4cea240927f62583
6
+ metadata.gz: a256682e2e237e067eb602add2644138a24cfbad1fce1c3d5b47173b8c1ae1184cff832799982bbff2127fdc2ff061ca2292047d41a15470c4c96b05975252c3
7
+ data.tar.gz: 4d7b2d79b6e75f5519cd3b55f010a14c8612e01ac4f859a8352e812242556f7b7f7ddbd53fdf793bfff7815ac6a080bbb71ce7690938890c93f8cda44002e6e6
data/Gemfile CHANGED
@@ -6,4 +6,5 @@ group :development do
6
6
  gem "bundler"
7
7
  gem "rake"
8
8
  gem "test-unit"
9
+ gem "test-unit-ruby-core"
9
10
  end
data/lib/timeout.rb CHANGED
@@ -23,29 +23,26 @@
23
23
  # Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
24
24
 
25
25
  module Timeout
26
- VERSION = "0.3.2"
26
+ VERSION = "0.4.1"
27
+
28
+ # Internal error raised to when a timeout is triggered.
29
+ class ExitException < Exception
30
+ def exception(*)
31
+ self
32
+ end
33
+ end
27
34
 
28
35
  # Raised by Timeout.timeout when the block times out.
29
36
  class Error < RuntimeError
30
- attr_reader :thread
37
+ def self.handle_timeout(message)
38
+ exc = ExitException.new(message)
31
39
 
32
- def self.catch(*args)
33
- exc = new(*args)
34
- exc.instance_variable_set(:@thread, Thread.current)
35
- exc.instance_variable_set(:@catch_value, exc)
36
- ::Kernel.catch(exc) {yield exc}
37
- end
38
-
39
- def exception(*)
40
- # TODO: use Fiber.current to see if self can be thrown
41
- if self.thread == Thread.current
42
- bt = caller
43
- begin
44
- throw(@catch_value, bt)
45
- rescue UncaughtThrowError
46
- end
40
+ begin
41
+ yield exc
42
+ rescue ExitException => e
43
+ raise new(message) if exc.equal?(e)
44
+ raise
47
45
  end
48
- super
49
46
  end
50
47
  end
51
48
 
@@ -195,8 +192,7 @@ module Timeout
195
192
  if klass
196
193
  perform.call(klass)
197
194
  else
198
- backtrace = Error.catch(&perform)
199
- raise Error, message, backtrace
195
+ Error.handle_timeout(message, &perform)
200
196
  end
201
197
  end
202
198
  module_function :timeout
data/timeout.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  name = File.basename(__FILE__, ".gemspec")
4
- version = ["lib", Array.new(name.count("-")+1, "..").join("/")].find do |dir|
4
+ version = ["lib", Array.new(name.count("-")+1, ".").join("/")].find do |dir|
5
5
  break File.foreach(File.join(__dir__, dir, "#{name.tr('-', '/')}.rb")) do |line|
6
6
  /^\s*VERSION\s*=\s*"(.*)"/ =~ line and break $1
7
7
  end rescue nil
@@ -21,6 +21,8 @@ Gem::Specification.new do |spec|
21
21
  spec.metadata["homepage_uri"] = spec.homepage
22
22
  spec.metadata["source_code_uri"] = spec.homepage
23
23
 
24
+ spec.required_ruby_version = '>= 2.6.0'
25
+
24
26
  spec.files = Dir.chdir(__dir__) do
25
27
  `git ls-files -z`.split("\x0").reject do |f|
26
28
  (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|rakelib)/|\.(?:git|travis|circleci)|appveyor|Rakefile)})
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timeout
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-16 00:00:00.000000000 Z
11
+ date: 2023-11-07 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Auto-terminate potentially long-running operations in Ruby.
14
14
  email:
@@ -37,7 +37,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 2.6.0
41
41
  required_rubygems_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
43
  - - ">="