Skip to content

Commit 281b250

Browse files
committed
Simplify logic to make GET_TIME shareable
1 parent a1d784c commit 281b250

File tree

1 file changed

+5
-10
lines changed

1 file changed

+5
-10
lines changed

lib/timeout.rb

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,11 @@ def self.handle_timeout(message) # :nodoc:
4646
# :stopdoc:
4747

4848
# We keep a private reference so that time mocking libraries won't break Timeout.
49-
GET_TIME =
50-
if defined?(Ractor.make_shareable)
51-
begin
52-
Ractor.make_shareable(Process.method(:clock_gettime))
53-
rescue # failed on Ruby 3.4
54-
Process.method(:clock_gettime)
55-
end
56-
else
57-
Process.method(:clock_gettime)
58-
end
49+
GET_TIME = Process.method(:clock_gettime)
50+
if defined?(Ractor.make_shareable)
51+
# Ractor.make_shareable(Method) only works on Ruby 4+
52+
Ractor.make_shareable(GET_TIME) rescue nil
53+
end
5954
private_constant :GET_TIME
6055

6156
class State

0 commit comments

Comments
 (0)