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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 851e38c367c7d9625dd267f049938fe5761b0580597ad73b18c069983a2d24aa
4
- data.tar.gz: 768f4eb26f2eb1c5c7fe0e251999fe9e58b1f52239d5e12c16440ac6b48e25d1
3
+ metadata.gz: cbc64bed11abfca3a665202b8ebe08e469bbf39d5428dc6f1dff28e25677a47e
4
+ data.tar.gz: 3477cba7467c684c2fca0a603905e53bb921a9e6b8a7f9e52f89b912d179494f
5
5
  SHA512:
6
- metadata.gz: d8ef40a988be4c1366a6fd344d34c7eaf1184cbb1d57d65549fc663c1731c9fee92714d8539d08e4b0f71cd391cfca1ae94d1d3816e31ec451a7604e48181bb0
7
- data.tar.gz: 95e5857db3003d69bd876e1db2ef12f2b22171310f0c802ac634beb16bea37ea425ce48bc53366eed70cd4788dad8977f98b48a1b071f6f16849297becc698c2
6
+ metadata.gz: 8e23355ad687ab0dca1dd481d37eb6d6a44e9d9a8489477a7e8bfcb7c6bebf6710834d7ae748a42686b6514953e0d702d37f8e11b7ee991b6ba86246ca77cb51
7
+ data.tar.gz: 75330a094648e97e36561b684e886309765bc9556fa1dce4bbf98430f241553352a0fbc43be553c790e8b6ffa6aa221115d7f7f42854e4d1d603d6268fb123ce
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyTimeoutSafe
4
- VERSION = '1.0.0'
4
+ VERSION = '1.0.1'
5
5
  end
@@ -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
- Thread.pass
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.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-27 00:00:00.000000000 Z
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