• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ruby-concurrency / concurrent-ruby / #2948

11 Aug 2014 02:52PM UTC coverage: 45.41% (-45.2%) from 90.621%
#2948

push

jdantonio
Removed Rbx from Travis allowed failures list.

1375 of 3028 relevant lines covered (45.41%)

0.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

46.15
/lib/concurrent/utility/timeout.rb
1
require 'rbconfig'
1✔
2
require 'thread'
1✔
3

4
require 'concurrent/errors'
1✔
5

6
module Concurrent
1✔
7

8
  # Wait the given number of seconds for the block operation to complete.
9
  #
10
  # @param [Integer] seconds The number of seconds to wait
11
  #
12
  # @return [Object] The result of the block operation
13
  #
14
  # @raise [Concurrent::TimeoutError] when the block operation does not complete
15
  #   in the allotted number of seconds.
16
  #
17
  # @note This method is intended to be a simpler and more reliable replacement
18
  # to the Ruby standard library `Timeout::timeout` method.
19
  def timeout(seconds)
1✔
20

21
    thread = Thread.new do
×
22
      Thread.current[:result] = yield
×
23
    end
24
    success = thread.join(seconds)
×
25

26
    if success
×
27
      return thread[:result]
×
28
    else
29
      raise TimeoutError
×
30
    end
31
  ensure
32
    Thread.kill(thread) unless thread.nil?
×
33
  end
34
  module_function :timeout
1✔
35
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc