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

jdantonio / concurrent-ruby / #714

23 May 2014 08:08PM UTC coverage: 40.697% (-56.5%) from 97.237%
#714

push

jdantonio
Merge pull request #96 from jdantonio/refactor/errors

Moved all custom errors into a single file and into the Concurrent module

17 of 18 new or added lines in 10 files covered. (94.44%)

1432 existing lines in 56 files now uncovered.

1028 of 2526 relevant lines covered (40.7%)

0.53 hits per line

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

59.38
/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 Executor
1✔
8

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

20
    protected
1✔
21

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

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

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

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

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

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

58
    # @!visibility private
59
    def work
1✔
UNCOV
60
      loop do
×
UNCOV
61
        task = @queue.pop
×
UNCOV
62
        break if task == :stop
×
63
        begin
UNCOV
64
          task.last.call(*task.first)
×
65
        rescue => ex
66
          # let it fail
67
        end
68
      end
UNCOV
69
      stopped_event.set
×
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