timeout 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +2 -4
- data/Rakefile +1 -1
- data/lib/timeout.rb +15 -16
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 62c9c45a4b7b1b7d4d0ee380d1827ee0718b895c368651be2c1a14acd5722e5a
|
4
|
+
data.tar.gz: 99344f3c5fd6808bc63fee9f5e96e21ffbb0ad495c1a5f0015cf5041e17ef74f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07f0da54b3057e69eef0a421fb5203710e5fe1837ba3c9ec234d81f77736fc524a18c57cd93ed07c403bdd585f588b764fd77bb71c39fed0bfd6af60b1bd9038
|
7
|
+
data.tar.gz: dcb89670a2e4593c64e39c6e6c1c50ef9df4d5810bab6272a82f7038a01b52efd45903489d587f40e60f609a39befe84be4b8bac333132406b14c87444f1c606
|
data/.github/workflows/test.yml
CHANGED
@@ -11,14 +11,12 @@ jobs:
|
|
11
11
|
os: [ ubuntu-latest, macos-latest ]
|
12
12
|
runs-on: ${{ matrix.os }}
|
13
13
|
steps:
|
14
|
-
- uses: actions/checkout@
|
14
|
+
- uses: actions/checkout@v2
|
15
15
|
- name: Set up Ruby
|
16
16
|
uses: ruby/setup-ruby@v1
|
17
17
|
with:
|
18
18
|
ruby-version: ${{ matrix.ruby }}
|
19
19
|
- name: Install dependencies
|
20
|
-
run:
|
21
|
-
gem install bundler --no-document
|
22
|
-
bundle install
|
20
|
+
run: bundle install
|
23
21
|
- name: Run test
|
24
22
|
run: rake test
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ end
|
|
9
9
|
|
10
10
|
task :sync_tool do
|
11
11
|
require 'fileutils'
|
12
|
-
FileUtils.cp "../ruby/tool/lib/
|
12
|
+
FileUtils.cp "../ruby/tool/lib/core_assertions.rb", "./test/lib"
|
13
13
|
FileUtils.cp "../ruby/tool/lib/envutil.rb", "./test/lib"
|
14
14
|
FileUtils.cp "../ruby/tool/lib/find_executable.rb", "./test/lib"
|
15
15
|
end
|
data/lib/timeout.rb
CHANGED
@@ -23,7 +23,7 @@
|
|
23
23
|
# Copyright:: (C) 2000 Information-technology Promotion Agency, Japan
|
24
24
|
|
25
25
|
module Timeout
|
26
|
-
VERSION = "0.
|
26
|
+
VERSION = "0.2.0".freeze
|
27
27
|
|
28
28
|
# Raised by Timeout.timeout when the block times out.
|
29
29
|
class Error < RuntimeError
|
@@ -32,6 +32,7 @@ module Timeout
|
|
32
32
|
def self.catch(*args)
|
33
33
|
exc = new(*args)
|
34
34
|
exc.instance_variable_set(:@thread, Thread.current)
|
35
|
+
exc.instance_variable_set(:@catch_value, exc)
|
35
36
|
::Kernel.catch(exc) {yield exc}
|
36
37
|
end
|
37
38
|
|
@@ -40,11 +41,11 @@ module Timeout
|
|
40
41
|
if self.thread == Thread.current
|
41
42
|
bt = caller
|
42
43
|
begin
|
43
|
-
throw(
|
44
|
+
throw(@catch_value, bt)
|
44
45
|
rescue UncaughtThrowError
|
45
46
|
end
|
46
47
|
end
|
47
|
-
|
48
|
+
super
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -73,12 +74,21 @@ module Timeout
|
|
73
74
|
# ensure to prevent the handling of the exception. For that reason, this
|
74
75
|
# method cannot be relied on to enforce timeouts for untrusted blocks.
|
75
76
|
#
|
77
|
+
# If a scheduler is defined, it will be used to handle the timeout by invoking
|
78
|
+
# Scheduler#timeout_after.
|
79
|
+
#
|
76
80
|
# Note that this is both a method of module Timeout, so you can <tt>include
|
77
81
|
# Timeout</tt> into your classes so they have a #timeout method, as well as
|
78
82
|
# a module method, so you can call it directly as Timeout.timeout().
|
79
|
-
def timeout(sec, klass = nil, message = nil) #:yield: +sec+
|
83
|
+
def timeout(sec, klass = nil, message = nil, &block) #:yield: +sec+
|
80
84
|
return yield(sec) if sec == nil or sec.zero?
|
85
|
+
|
81
86
|
message ||= "execution expired".freeze
|
87
|
+
|
88
|
+
if Fiber.respond_to?(:current_scheduler) && (scheduler = Fiber.current_scheduler)&.respond_to?(:timeout_after)
|
89
|
+
return scheduler.timeout_after(sec, klass || Error, message, &block)
|
90
|
+
end
|
91
|
+
|
82
92
|
from = "from #{caller_locations(1, 1)[0]}" if $DEBUG
|
83
93
|
e = Error
|
84
94
|
bl = proc do |exception|
|
@@ -106,6 +116,7 @@ module Timeout
|
|
106
116
|
begin
|
107
117
|
bl.call(klass)
|
108
118
|
rescue klass => e
|
119
|
+
message = e.message
|
109
120
|
bt = e.backtrace
|
110
121
|
end
|
111
122
|
else
|
@@ -120,15 +131,3 @@ module Timeout
|
|
120
131
|
|
121
132
|
module_function :timeout
|
122
133
|
end
|
123
|
-
|
124
|
-
def timeout(*args, &block)
|
125
|
-
warn "Object##{__method__} is deprecated, use Timeout.timeout instead.", uplevel: 1
|
126
|
-
Timeout.timeout(*args, &block)
|
127
|
-
end
|
128
|
-
|
129
|
-
# Another name for Timeout::Error, defined for backwards compatibility with
|
130
|
-
# earlier versions of timeout.rb.
|
131
|
-
TimeoutError = Timeout::Error
|
132
|
-
class Object
|
133
|
-
deprecate_constant :TimeoutError
|
134
|
-
end
|
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.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-10-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Auto-terminate potentially long-running operations in Ruby.
|
14
14
|
email:
|
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
49
|
- !ruby/object:Gem::Version
|
50
50
|
version: '0'
|
51
51
|
requirements: []
|
52
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.3.0.dev
|
53
53
|
signing_key:
|
54
54
|
specification_version: 4
|
55
55
|
summary: Auto-terminate potentially long-running operations in Ruby.
|