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

ruby-concurrency / concurrent-ruby / #2776

05 Oct 2014 10:16PM UTC coverage: 90.631% (-4.2%) from 94.81%
#2776

push

jdantonio
Merge pull request #158 from obrok/promise-composition

Promise composition

15 of 15 new or added lines in 1 file covered. (100.0%)

145 existing lines in 16 files now uncovered.

2757 of 3042 relevant lines covered (90.63%)

378.34 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
125✔
17
      @thread = nil
125✔
18
      init_executor
125✔
19
    end
20

21
    protected
1✔
22

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

29
    # @!visibility private
30
    def shutdown_execution
1✔
31
      @queue << :stop
16✔
32
      stopped_event.set unless alive?
16✔
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?
255✔
44
    end
45

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

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

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