Skip to content

Commit

Permalink
⚡️ [RUMF-1030] Decrease BoundedBuffer limitation to 500 (#1242)
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque authored Jan 5, 2022
1 parent d1f0d35 commit 61099bd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
9 changes: 5 additions & 4 deletions packages/core/src/tools/boundedBuffer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ describe('BoundedBuffer', () => {
expect(spy.calls.count()).toBe(1)
})

it('store only the N last callbacks', () => {
it('store at most 500 callbacks', () => {
const spy = jasmine.createSpy<() => void>()
const buffered = new BoundedBuffer(5)
const buffered = new BoundedBuffer()
const limit = 500

for (let i = 0; i < 10; i += 1) {
for (let i = 0; i < limit + 1; i += 1) {
buffered.add(spy)
}

buffered.drain()
expect(spy.calls.count()).toEqual(5)
expect(spy.calls.count()).toEqual(limit)
})
})
6 changes: 2 additions & 4 deletions packages/core/src/tools/boundedBuffer.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
const DEFAULT_LIMIT = 10_000
const BUFFER_LIMIT = 500

export class BoundedBuffer {
private buffer: Array<() => void> = []

constructor(private limit: number = DEFAULT_LIMIT) {}

add(callback: () => void) {
const length = this.buffer.push(callback)
if (length > this.limit) {
if (length > BUFFER_LIMIT) {
this.buffer.splice(0, 1)
}
}
Expand Down

0 comments on commit 61099bd

Please sign in to comment.