ruby_timeout_safe 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/ruby_timeout_safe/version.rb +1 -1
- data/lib/ruby_timeout_safe.rb +3 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbc64bed11abfca3a665202b8ebe08e469bbf39d5428dc6f1dff28e25677a47e
|
4
|
+
data.tar.gz: 3477cba7467c684c2fca0a603905e53bb921a9e6b8a7f9e52f89b912d179494f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e23355ad687ab0dca1dd481d37eb6d6a44e9d9a8489477a7e8bfcb7c6bebf6710834d7ae748a42686b6514953e0d702d37f8e11b7ee991b6ba86246ca77cb51
|
7
|
+
data.tar.gz: 75330a094648e97e36561b684e886309765bc9556fa1dce4bbf98430f241553352a0fbc43be553c790e8b6ffa6aa221115d7f7f42854e4d1d603d6268fb123ce
|
data/lib/ruby_timeout_safe.rb
CHANGED
@@ -8,6 +8,8 @@ module RubyTimeoutSafe
|
|
8
8
|
def self.timeout(seconds = nil)
|
9
9
|
return yield if seconds.nil? || seconds.zero?
|
10
10
|
|
11
|
+
raise ArgumentError, 'timeout value must be at least 0.1 second' if seconds < 0.1
|
12
|
+
|
11
13
|
current_thread = Thread.current
|
12
14
|
|
13
15
|
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
@@ -16,7 +18,7 @@ module RubyTimeoutSafe
|
|
16
18
|
elapsed_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start_time
|
17
19
|
break if elapsed_time >= seconds
|
18
20
|
|
19
|
-
|
21
|
+
sleep(0.05) # Sleep briefly to prevent busy-waiting
|
20
22
|
end
|
21
23
|
current_thread.raise Timeout::Error, 'execution expired'
|
22
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_timeout_safe
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- sebi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
ruby-timeout-safe is a Ruby library that provides a safe and reliable timeout
|