Skip to content

Commit c6b81ae

Browse files
committed
test: breaking changes
1 parent d3945d6 commit c6b81ae

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

pkg/utils/mailbox/mailbox.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ type Mailbox[T any] struct {
1717

1818
// capacity - number of items the mailbox can buffer
1919
// NOTE: if the capacity is 1, it's possible that an empty Retrieve may occur after a notification.
20-
capacity uint64
20+
capacity uint32
2121
// onCloseFn is a hook used to stop monitoring, if non-nil
2222
onCloseFn func()
23+
24+
nonBreakingChange bool
2325
}
2426

2527
// NewHighCapacity create a new mailbox with a capacity
@@ -33,15 +35,16 @@ func NewSingle[T any]() *Mailbox[T] { return New[T](1) }
3335

3436
// New creates a new mailbox instance. If name is non-empty, it must be unique and calling Start will launch
3537
// prometheus metric monitor that periodically reports mailbox load until Close() is called.
36-
func New[T any](capacity uint64) *Mailbox[T] {
38+
func New[T any](capacity uint32) *Mailbox[T] {
3739
queueCap := capacity
3840
if queueCap == 0 {
3941
queueCap = 100
4042
}
4143
return &Mailbox[T]{
42-
chNotify: make(chan struct{}, 1),
43-
queue: make([]T, 0, queueCap),
44-
capacity: capacity,
44+
chNotify: make(chan struct{}, 1),
45+
queue: make([]T, 0, queueCap),
46+
capacity: capacity,
47+
nonBreakingChange: false,
4548
}
4649
}
4750

@@ -59,7 +62,7 @@ func (m *Mailbox[T]) Close() error {
5962

6063
func (m *Mailbox[T]) onClose(fn func()) { m.onCloseFn = fn }
6164

62-
func (m *Mailbox[T]) load() (capacity uint64, loadPercent float64) {
65+
func (m *Mailbox[T]) load() (capacity uint32, loadPercent float64) {
6366
capacity = m.capacity
6467
loadPercent = 100 * float64(m.queueLen.Load()) / float64(capacity)
6568
return
@@ -71,7 +74,7 @@ func (m *Mailbox[T]) Deliver(x T) (wasOverCapacity bool) {
7174
defer m.mu.Unlock()
7275

7376
m.queue = append([]T{x}, m.queue...)
74-
if uint64(len(m.queue)) > m.capacity && m.capacity > 0 {
77+
if uint32(len(m.queue)) > m.capacity && m.capacity > 0 {
7578
m.queue = m.queue[:len(m.queue)-1]
7679
wasOverCapacity = true
7780
} else {

0 commit comments

Comments
 (0)