refactor: dedupe worker choice strategy options handling code
[poolifier.git] / src / deque.ts
index 2eae8034845789b4991c3d1435c24f7050726c42..00f60e6f7256c5204969ac827d4533cfaf177994 100644 (file)
@@ -76,14 +76,15 @@ export class Deque<T> {
    */
   public pop (): T | undefined {
     if (this.head == null) {
-      return undefined
+      return
     }
     const tail = this.tail
-    this.tail = (this.tail as Node<T>).prev
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+    this.tail = this.tail!.prev
     if (this.tail == null) {
-      this.head = undefined
+      delete this.head
     } else {
-      this.tail.next = undefined
+      delete this.tail.next
     }
     --this.size
     return tail?.data
@@ -96,14 +97,14 @@ export class Deque<T> {
    */
   public shift (): T | undefined {
     if (this.head == null) {
-      return undefined
+      return
     }
     const head = this.head
     this.head = this.head.next
     if (this.head == null) {
-      this.tail = undefined
+      delete this.tail
     } else {
-      this.head.prev = undefined
+      delete this.head.prev
     }
     --this.size
     return head?.data
@@ -129,8 +130,8 @@ export class Deque<T> {
    * Clears the deque.
    */
   public clear (): void {
-    this.head = undefined
-    this.tail = undefined
+    delete this.head
+    delete this.tail
     this.size = 0
     this.maxSize = 0
   }
@@ -155,7 +156,8 @@ export class Deque<T> {
           value: node.data,
           done: false
         }
-        node = node.next as Node<T>
+        // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+        node = node.next!
         return ret
       }
     }
@@ -183,7 +185,8 @@ export class Deque<T> {
               value: node.data,
               done: false
             }
-            node = node.prev as Node<T>
+            // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+            node = node.prev!
             return ret
           }
         }