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

ruby-concurrency / concurrent-ruby / #2712

10 Jul 2014 01:54PM UTC coverage: 91.261% (-5.0%) from 96.218%
#2712

push

jdantonio
Merge pull request #135 from obrok/patch-1

Fix unbalanced parenthesis in README

2360 of 2586 relevant lines covered (91.26%)

413.27 hits per line

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

97.06
/lib/concurrent/executor/ruby_single_thread_executor.rb
1
require_relative 'executor'
1✔
2

3
module Concurrent
1✔
4

5
  # @!macro single_thread_executor
6
  class RubySingleThreadExecutor
1✔
7
    include RubyExecutor
1✔
8
    include SerialExecutor
1✔
9

10
    # Create a new thread pool.
11
    #
12
    # @see http://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html
13
    # @see http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Executors.html
14
    # @see http://docs.oracle.com/javase/8/docs/api/java/util/concurrent/ExecutorService.html
15
    def initialize(opts = {})
1✔
16
      @queue = Queue.new
124✔
17
      @thread = nil
124✔
18
      init_executor
124✔
19
    end
20

21
    protected
1✔
22

23
    # @!visibility private
24
    def execute(*args, &task)
1✔
25
      supervise
201✔
26
      @queue << [args, task]
201✔
27
    end
28

29
    # @!visibility private
30
    def shutdown_execution
1✔
31
      @queue << :stop
15✔
32
      stopped_event.set unless alive?
15✔
33
    end
34

35
    # @!visibility private
36
    def kill_execution
1✔
37
      @queue.clear
37✔
38
      @thread.kill if alive?
37✔
39
    end
40

41
    # @!visibility private
42
    def alive?
1✔
43
      @thread && @thread.alive?
253✔
44
    end
45

46
    # @!visibility private
47
    def supervise
1✔
48
      @thread = new_worker_thread unless alive?
201✔
49
    end
50

51
    # @!visibility private
52
    def new_worker_thread
1✔
53
      Thread.new do
97✔
54
        Thread.current.abort_on_exception = false
79✔
55
        work
79✔
56
      end
57
    end
58

59
    # @!visibility private
60
    def work
1✔
61
      loop do
79✔
62
        task = @queue.pop
156✔
63
        break if task == :stop
119✔
64
        begin
65
          task.last.call(*task.first)
109✔
66
        rescue => ex
67
          # let it fail
68
          log DEBUG, ex
×
69
        end
70
      end
71
      stopped_event.set
10✔
72
    end
73
  end
74
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