• 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

35.71
/lib/concurrent/collection/ring_buffer.rb
1
module Concurrent
1✔
2

3
  # non-thread safe buffer
4
  class RingBuffer
1✔
5

6
    def initialize(capacity)
1✔
UNCOV
7
      @buffer = Array.new(capacity)
×
UNCOV
8
      @first = @last = 0
×
UNCOV
9
      @count = 0
×
10
    end
11

12

13
    # @return [Integer] the capacity of the buffer
14
    def capacity
1✔
UNCOV
15
      @buffer.size
×
16
    end
17

18
    # @return [Integer] the number of elements currently in the buffer
19
    def count
1✔
UNCOV
20
      @count
×
21
    end
22

23
    # @return [Boolean] true if buffer is empty, false otherwise
24
    def empty?
1✔
UNCOV
25
      @count == 0
×
26
    end
27

28
    # @return [Boolean] true if buffer is full, false otherwise
29
    def full?
1✔
UNCOV
30
      @count == capacity
×
31
    end
32

33
    # @param [Object] value
34
    # @return [Boolean] true if value has been inserted, false otherwise
35
    def offer(value)
1✔
UNCOV
36
      return false if full?
×
37

UNCOV
38
      @buffer[@last] = value
×
UNCOV
39
      @last = (@last + 1) % @buffer.size
×
UNCOV
40
      @count += 1
×
UNCOV
41
      true
×
42
    end
43

44
    # @return [Object] the first available value and removes it from the buffer. If buffer is empty returns nil
45
    def poll
1✔
UNCOV
46
      result = @buffer[@first]
×
UNCOV
47
      @buffer[@first] = nil
×
UNCOV
48
      @first = (@first + 1) % @buffer.size
×
UNCOV
49
      @count -= 1
×
UNCOV
50
      result
×
51
    end
52

53
    # @return [Object] the first available value and without removing it from the buffer. If buffer is empty returns nil
54
    def peek
1✔
UNCOV
55
      @buffer[@first]
×
56
    end
57

58
  end
59
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