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

ruby-concurrency / concurrent-ruby / #2835

05 Oct 2014 10:16PM UTC coverage: 45.201% (-49.6%) from 94.81%
#2835

push

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

Promise composition

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

1514 existing lines in 84 files now uncovered.

1375 of 3042 relevant lines covered (45.2%)

0.66 hits per line

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

34.78
/lib/concurrent/executor/per_thread_executor.rb
1
require 'concurrent/atomics'
1✔
2
require 'concurrent/executor/executor'
1✔
3

4
module Concurrent
1✔
5

6
  # An executor service in which every operation spawns a new,
7
  # independently operating thread.
8
  #
9
  # This is perhaps the most inefficient executor service in this
10
  # library. It exists mainly for testing an debugging. Thread creation
11
  # and management is expensive in Ruby and this executor performs no
12
  # resource pooling. This can be very beneficial during testing and
13
  # debugging because it decouples the using code from the underlying
14
  # executor implementation. In production this executor will likely
15
  # lead to suboptimal performance.
16
  #
17
  # @note Intended for use primarily in testing and debugging.
18
  class PerThreadExecutor
1✔
19
    include Executor
1✔
20

21
    # Creates a new executor
22
    def initialize
1✔
UNCOV
23
      @running = Concurrent::AtomicBoolean.new(true)
×
UNCOV
24
      @stopped = Concurrent::Event.new
×
UNCOV
25
      @count = Concurrent::AtomicFixnum.new(0)
×
26
    end
27

28
    # @!macro executor_method_post
29
    def self.post(*args)
1✔
UNCOV
30
      raise ArgumentError.new('no block given') unless block_given?
×
UNCOV
31
      Thread.new(*args) do
×
UNCOV
32
        Thread.current.abort_on_exception = false
×
UNCOV
33
        yield(*args)
×
34
      end
UNCOV
35
      true
×
36
    end
37

38
    # @!macro executor_method_left_shift
39
    def self.<<(task)
1✔
UNCOV
40
      post(&task)
×
UNCOV
41
      self
×
42
    end
43

44
    # @!macro executor_method_post
45
    def post(*args, &task)
1✔
UNCOV
46
      raise ArgumentError.new('no block given') unless block_given?
×
UNCOV
47
      return false unless running?
×
UNCOV
48
      @count.increment
×
UNCOV
49
      Thread.new(*args) do
×
UNCOV
50
        Thread.current.abort_on_exception = false
×
51
        begin
UNCOV
52
          yield(*args)
×
53
        ensure
UNCOV
54
          @count.decrement
×
UNCOV
55
          @stopped.set if @running.false? && @count.value == 0
×
56
        end
57
      end
58
    end
59

60
    # @!macro executor_method_left_shift
61
    def <<(task)
1✔
UNCOV
62
      post(&task)
×
UNCOV
63
      self
×
64
    end
65

66
    # @!macro executor_method_running_question
67
    def running?
1✔
UNCOV
68
      @running.true?
×
69
    end
70

71
    # @!macro executor_method_shuttingdown_question
72
    def shuttingdown?
1✔
73
      @running.false? && ! @stopped.set?
×
74
    end
75

76
    # @!macro executor_method_shutdown_question
77
    def shutdown?
1✔
78
      @stopped.set?
×
79
    end
80

81
    # @!macro executor_method_shutdown
82
    def shutdown
1✔
UNCOV
83
      @running.make_false
×
UNCOV
84
      @stopped.set if @count.value == 0
×
UNCOV
85
      true
×
86
    end
87

88
    # @!macro executor_method_kill
89
    def kill
1✔
UNCOV
90
      @running.make_false
×
UNCOV
91
      @stopped.set
×
UNCOV
92
      true
×
93
    end
94

95
    # @!macro executor_method_wait_for_termination
96
    def wait_for_termination(timeout = nil)
1✔
UNCOV
97
      @stopped.wait(timeout)
×
98
    end
99
  end
100
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