9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/ruby_llm/mcp/native/transports/support/timeout.rb', line 9
def with_timeout(seconds, request_id: nil)
result = nil
exception = nil
worker = Thread.new do
result = yield
rescue StandardError => e
exception = e
end
if worker.join(seconds)
raise exception if exception
result
else
worker.kill worker.join(0.1)
raise RubyLLM::MCP::Errors::TimeoutError.new(
message: "Request timed out after #{seconds} seconds",
request_id: request_id
)
end
end
|