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

ruby-concurrency / concurrent-ruby / #2863

29 Jul 2014 08:21PM UTC coverage: 72.418% (-24.0%) from 96.444%
#2863

push

Petr Chalupa
Merge pull request #132 from ruby-concurrency/actress

Adding features to Actors

303 of 596 new or added lines in 35 files covered. (50.84%)

2132 of 2944 relevant lines covered (72.42%)

146.84 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✔
NEW
12
          super core, subsequent
×
NEW
13
          @buffer                     = []
×
NEW
14
          @receive_envelope_scheduled = false
×
15
        end
16

17
        def on_envelope(envelope)
1✔
NEW
18
          @buffer.push envelope
×
NEW
19
          process_envelopes?
×
NEW
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✔
NEW
28
          unless @buffer.empty? || @receive_envelope_scheduled
×
NEW
29
            @receive_envelope_scheduled = true
×
NEW
30
            process_envelope
×
31
          end
32
        end
33

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

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