fix: fix iteration in fixed queue if start > size
[poolifier.git] / src / circular-buffer.ts
index a56cd09d551e67cc865ac4e40950cb6988b76362..7abb982ea6adb3ebcd2881efbb9d1b7ef8c66682 100644 (file)
@@ -65,14 +65,14 @@ export class CircularBuffer {
    * @returns Number from buffer.
    */
   public get (): number | undefined {
-    const data = this.items[this.readIdx]
-    if (data === -1) {
+    const number = this.items[this.readIdx]
+    if (number === -1) {
       return
     }
     this.items[this.readIdx] = -1
     this.readIdx = this.readIdx === this.maxArrayIdx ? 0 : this.readIdx + 1
     --this.size
-    return data
+    return number
   }
 
   /**
@@ -87,7 +87,7 @@ export class CircularBuffer {
   private checkSize (size: number): void {
     if (!Number.isSafeInteger(size)) {
       throw new TypeError(
-        `Invalid circular buffer size: ${size} is not an integer`
+        `Invalid circular buffer size: '${size}' is not an integer`
       )
     }
     if (size < 0) {