timeout 0.3.1 → 0.4.0

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 +17 -21
  4. data/timeout.gemspec +1 -1
  5. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a6594a086deee17da9d946b2f6068596050273da5171289b9f89d0ceb77a7b6
4
- data.tar.gz: 6fee2749f06aa755490e9865ce0e4a398c3f06a1b93d1542851b496f7b85d423
3
+ metadata.gz: 19bdc6e927cfc023688f6d4e08a55b1d483257bd450db6e203e1965158bb7ed4
4
+ data.tar.gz: 742db38b61ab633ca1baef82a73338b0e2d9e4a0d10bdf3908fc8ed87d04f4c2
5
5
  SHA512:
6
- metadata.gz: c99b16bbdcfb0c08b46394ffc02da7df7e0f6377ff41f4d4ff6283301e68e316ed38b9a1efbca97a42308f49537cc68ee9a616c2b440bde671c92a26fdd4cfb1
7
- data.tar.gz: 7af440551ea27f95a2769dd046339073e2d15bd0ae0e0c6a2922666b7091775083121a575b9178c939acdb0d903d1b591c725dc9bd804a95cc1954ae61af8b30
6
+ metadata.gz: 6836956b4e59cebd6a14d0a9d3857c700a1bd65a566ff1d41be3657631b3e33a443910d4123dae1b81eaa81198896442f5c0f2a32e3b7182ad2144fdc39cbcfc
7
+ data.tar.gz: a7a4a1a176dcbf09297133476914684db3ae8c77c37d510af6d6200279f17fa0b1829c6b2ad19fa29b6be1c62f9b60aba6e362c47affcd71ec36ce934e8a391a
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.1"
26
+ VERSION = "0.4.0"
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
 
@@ -120,7 +117,7 @@ module Timeout
120
117
  requests.reject!(&:done?)
121
118
  end
122
119
  end
123
- ThreadGroup::Default.add(watcher)
120
+ ThreadGroup::Default.add(watcher) unless watcher.group.enclosed?
124
121
  watcher.name = "Timeout stdlib thread"
125
122
  watcher.thread_variable_set(:"\0__detached_thread__", true)
126
123
  watcher
@@ -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
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.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yukihiro Matsumoto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-05 00:00:00.000000000 Z
11
+ date: 2023-06-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Auto-terminate potentially long-running operations in Ruby.
14
14
  email:
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  requirements: []
47
- rubygems_version: 3.4.0.dev
47
+ rubygems_version: 3.5.0.dev
48
48
  signing_key:
49
49
  specification_version: 4
50
50
  summary: Auto-terminate potentially long-running operations in Ruby.