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

ruby-concurrency / concurrent-ruby / #2764

08 Dec 2014 03:40PM UTC coverage: 91.388% (-0.4%) from 91.753%
#2764

push

jdantonio
Merge pull request #201 from rkday/fallback_handling

Posting to a shutdown thread pool - JRuby consistency and better naming

18 of 26 new or added lines in 5 files covered. (69.23%)

212 existing lines in 36 files now uncovered.

2812 of 3077 relevant lines covered (91.39%)

369.8 hits per line

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

91.89
/lib/concurrent/executor/ruby_thread_pool_worker.rb
1
require 'thread'
1✔
2
require 'concurrent/logging'
1✔
3

4
module Concurrent
1✔
5

6
  # @!visibility private
7
  class RubyThreadPoolWorker
1✔
8
    include Logging
1✔
9

10
    # @!visibility private
11
    def initialize(queue, parent)
1✔
12
      @queue = queue
11,778✔
13
      @parent = parent
11,778✔
14
      @mutex = Mutex.new
11,778✔
15
      @last_activity = Time.now.to_f
11,778✔
16
    end
17

18
    # @!visibility private
19
    def dead?
1✔
20
      return @mutex.synchronize do
231✔
21
        @thread.nil? ? false : ! @thread.alive?
231✔
22
      end
23
    end
24

25
    # @!visibility private
26
    def last_activity
1✔
27
      @mutex.synchronize { @last_activity }
456✔
28
    end
29

30
    def status
1✔
UNCOV
31
      @mutex.synchronize do
×
UNCOV
32
        return 'not running' if @thread.nil?
×
UNCOV
33
        @thread.status
×
34
      end
35
    end
36

37
    # @!visibility private
38
    def kill
1✔
39
      @mutex.synchronize do
318✔
40
        Thread.kill(@thread) unless @thread.nil?
318✔
41
        @thread = nil
318✔
42
      end
43
    end
44

45
    # @!visibility private
46
    def run(thread = Thread.current)
1✔
47
      @mutex.synchronize do
10,000✔
48
        raise StandardError.new('already running') unless @thread.nil?
10,000✔
49
        @thread = thread
10,000✔
50
      end
51

52
      loop do
10,000✔
53
        task = @queue.pop
13,221✔
54
        if task == :stop
3,697✔
55
          @thread = nil
293✔
56
          @parent.on_worker_exit(self)
293✔
57
          break
293✔
58
        end
59

60
        begin
61
          task.last.call(*task.first)
3,404✔
62
        rescue => ex
63
          # let it fail
64
          log DEBUG, ex
20✔
65
        ensure
66
          @last_activity = Time.now.to_f
3,404✔
67
          @parent.on_end_task
3,403✔
68
        end
69
      end
70
    end
71
  end
72
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