WIP
This commit is contained in:
@@ -13,7 +13,7 @@ test("RingBuffer", () => {
|
||||
expect(ring.buffer.length).toBe(4);
|
||||
|
||||
for (let i = 0; i < 8; i++) {
|
||||
expect(claim(ring, (i) => i)).toBe(ring.buffer[i % 4]);
|
||||
expect(claim(ring, (_) => {})).toBe(ring.buffer[i % 4]);
|
||||
}
|
||||
|
||||
expect(ring.cursor).toBe(0);
|
||||
|
||||
@@ -26,9 +26,10 @@ export function createRingBuffer<T extends object>(
|
||||
};
|
||||
}
|
||||
|
||||
export function claim<T>(ring: RingBuffer<T>, reset: (instance: T) => T): T {
|
||||
export function claim<T>(ring: RingBuffer<T>, reset: (instance: T) => void): T {
|
||||
const instance = ring.buffer[ring.cursor];
|
||||
reset(instance);
|
||||
ring.cursor = (ring.cursor + 1) & ring.mask;
|
||||
|
||||
return reset(instance);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16">
|
||||
<rect width="16" height="16" fill="#ff00ff"/>
|
||||
<rect width="8" height="8" fill="#000000"/>
|
||||
<rect x="8" y="8" width="8" height="8" fill="#000000"/>
|
||||
<rect width="16" height="16" fill="#ff00ff" />
|
||||
<rect width="8" height="8" fill="#000000" />
|
||||
<rect x="8" y="8" width="8" height="8" fill="#000000" />
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 220 B After Width: | Height: | Size: 226 B |
Reference in New Issue
Block a user