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

jdantonio / concurrent-ruby / #748

24 Apr 2014 12:31AM UTC coverage: 78.31% (-19.5%) from 97.805%
#748

push

jdantonio
Attempting to fix a brittle test of Concurrent::timer.

1928 of 2462 relevant lines covered (78.31%)

409.47 hits per line

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

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

4
module Concurrent
1✔
5

6
  # Error raised when an operations times out.
7
  TimeoutError = Class.new(StandardError)
1✔
8

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

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

27
    if success
26✔
28
      return thread[:result]
26✔
29
    else
30
      raise TimeoutError
×
31
    end
32
  ensure
33
    Thread.kill(thread) unless thread.nil?
38✔
34
  end
35
  module_function :timeout
1✔
36
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