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

ruby-concurrency / concurrent-ruby / #2743

04 Mar 2015 02:59AM UTC coverage: 45.152% (-50.4%) from 95.548%
#2743

push

jdantonio
Merge pull request #258 from ruby-concurrency/clock_time

Closes #256

23 of 69 new or added lines in 7 files covered. (33.33%)

1563 existing lines in 88 files now uncovered.

1425 of 3156 relevant lines covered (45.15%)

0.65 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
6
      # scheduled at any given time. Others are kept in buffer until another one
7
      # can be scheduled. This effectively means that messages handled by
8
      # behaviours before buffer have higher priority and they can be processed
9
      # before messages arriving into buffer. This allows for the processing of
10
      # internal actor messages like (`:link`, `:supervise`) first.
11
      class Buffer < Abstract
1✔
12
        def initialize(core, subsequent)
1✔
UNCOV
13
          super core, subsequent
×
UNCOV
14
          @buffer                     = []
×
UNCOV
15
          @receive_envelope_scheduled = false
×
16
        end
17

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

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

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

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