• 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

33.33
/lib/concurrent/actor/behaviour/buffer.rb
1
module Concurrent
1✔
2
  module Actor
1✔
3
    module Behaviour
1✔
4

5
      # Any message reaching this behaviour is buffered. Only one message is is scheduled
6
      # at any given time. Others are kept in buffer until another one can be scheduled.
7
      # This effective means that messages handled by behaviours before buffer have higher priority
8
      # and they can be processed before messages arriving into buffer. This allows to
9
      # process internal actor messages like (`:link`, `:supervise`) processed first.
10
      class Buffer < Abstract
1✔
11
        def initialize(core, subsequent)
1✔
UNCOV
12
          super core, subsequent
×
UNCOV
13
          @buffer                     = []
×
UNCOV
14
          @receive_envelope_scheduled = false
×
15
        end
16

17
        def on_envelope(envelope)
1✔
UNCOV
18
          @buffer.push envelope
×
UNCOV
19
          process_envelopes?
×
UNCOV
20
          MESSAGE_PROCESSED
×
21
        end
22

23
        # Ensures that only one envelope processing is scheduled with #schedule_execution,
24
        # this allows other scheduled blocks to be executed before next envelope processing.
25
        # Simply put this ensures that Core is still responsive to internal calls (like add_child)
26
        # even though the Actor is flooded with messages.
27
        def process_envelopes?
1✔
UNCOV
28
          unless @buffer.empty? || @receive_envelope_scheduled
×
UNCOV
29
            @receive_envelope_scheduled = true
×
UNCOV
30
            process_envelope
×
31
          end
32
        end
33

34
        def process_envelope
1✔
UNCOV
35
          envelope = @buffer.shift
×
UNCOV
36
          return nil unless envelope
×
UNCOV
37
          pass envelope
×
38
        ensure
UNCOV
39
          @receive_envelope_scheduled = false
×
UNCOV
40
          core.schedule_execution { process_envelopes? }
×
41
        end
42

43
        def on_event(event)
1✔
UNCOV
44
          case event
×
45
          when :terminated, :restarted
UNCOV
46
            @buffer.each { |envelope| reject_envelope envelope }
×
UNCOV
47
            @buffer.clear
×
48
          end
UNCOV
49
          super event
×
50
        end
51
      end
52
    end
53
  end
54
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